Java Code Examples for com.amazonaws.services.kms.AWSKMS#createKey()

The following examples show how to use com.amazonaws.services.kms.AWSKMS#createKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CreateCustomerMasterKey.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    AWSKMS kmsClient = AWSKMSClientBuilder.standard().build();

    // Create a CMK

    String desc = "Key for protecting critical data";

    CreateKeyRequest req = new CreateKeyRequest().withDescription(desc);
    CreateKeyResult result = kmsClient.createKey(req);

    System.out.printf(
        "Created a customer master key with id \"%s\"%n",
        result.getKeyMetadata().getArn()
    );
}
 
Example 2
Source File: LocalstackContainerTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void kmsKeyCreationTest() {
    AWSKMS awskms = AWSKMSClientBuilder.standard()
        .withEndpointConfiguration(localstack.getEndpointConfiguration(KMS))
        .withCredentials(localstack.getDefaultCredentialsProvider())
        .build();

    String desc = String.format("AWS CMK Description");
    Tag createdByTag = new Tag().withTagKey("CreatedBy").withTagValue("StorageService");
    CreateKeyRequest req = new CreateKeyRequest().withDescription(desc).withTags(createdByTag);
    CreateKeyResult key = awskms.createKey(req);

    assertEquals("AWS KMS Customer Managed Key should be created ", key.getKeyMetadata().getDescription(), desc);
}