Search in sources :

Example 1 with CreateKeyResponse

use of software.amazon.awssdk.services.kms.model.CreateKeyResponse in project aws-doc-sdk-examples by awsdocs.

the class CreateCustomerKey method createKey.

// snippet-start:[kms.java2_create_key.main]
public static String createKey(KmsClient kmsClient, String keyDesc) {
    try {
        CreateKeyRequest keyRequest = CreateKeyRequest.builder().description(keyDesc).customerMasterKeySpec(CustomerMasterKeySpec.SYMMETRIC_DEFAULT).keyUsage("ENCRYPT_DECRYPT").build();
        CreateKeyResponse result = kmsClient.createKey(keyRequest);
        System.out.printf("Created a customer key with id \"%s\"%n", result.keyMetadata().arn());
        return result.keyMetadata().keyId();
    } catch (KmsException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    return "";
}
Also used : KmsException(software.amazon.awssdk.services.kms.model.KmsException) CreateKeyRequest(software.amazon.awssdk.services.kms.model.CreateKeyRequest) CreateKeyResponse(software.amazon.awssdk.services.kms.model.CreateKeyResponse)

Aggregations

CreateKeyRequest (software.amazon.awssdk.services.kms.model.CreateKeyRequest)1 CreateKeyResponse (software.amazon.awssdk.services.kms.model.CreateKeyResponse)1 KmsException (software.amazon.awssdk.services.kms.model.KmsException)1