Search in sources :

Example 1 with CreateKeyRequest

use of com.amazonaws.services.kms.model.CreateKeyRequest in project aws-doc-sdk-examples by awsdocs.

the class S3EncryptV2 method putEncryptedData3_Kms.

public static void putEncryptedData3_Kms() {
    // snippet-start:[s3.java.s3_cse-v2.kms]
    AWSKMS kmsClient = AWSKMSClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build();
    // create CMK for for testing this example
    CreateKeyRequest createKeyRequest = new CreateKeyRequest();
    CreateKeyResult createKeyResult = kmsClient.createKey(createKeyRequest);
    // specify an Amazon KMS customer master key (CMK) ID
    String keyId = createKeyResult.getKeyMetadata().getKeyId();
    String s3ObjectKey = "EncryptedContent3.txt";
    String s3ObjectContent = "This is the 3rd content to encrypt";
    AmazonS3EncryptionV2 s3Encryption = AmazonS3EncryptionClientV2Builder.standard().withRegion(Regions.US_WEST_2).withCryptoConfiguration(new CryptoConfigurationV2().withCryptoMode(CryptoMode.StrictAuthenticatedEncryption)).withEncryptionMaterialsProvider(new KMSEncryptionMaterialsProvider(keyId)).build();
    s3Encryption.putObject(bucketName, s3ObjectKey, s3ObjectContent);
    System.out.println(s3Encryption.getObjectAsString(bucketName, s3ObjectKey));
    // schedule deletion of CMK generated for testing
    ScheduleKeyDeletionRequest scheduleKeyDeletionRequest = new ScheduleKeyDeletionRequest().withKeyId(keyId).withPendingWindowInDays(7);
    kmsClient.scheduleKeyDeletion(scheduleKeyDeletionRequest);
    s3Encryption.shutdown();
    kmsClient.shutdown();
// snippet-end:[s3.java.s3_cse-v2.kms]
}
Also used : AmazonS3EncryptionV2(com.amazonaws.services.s3.AmazonS3EncryptionV2) ScheduleKeyDeletionRequest(com.amazonaws.services.kms.model.ScheduleKeyDeletionRequest) CreateKeyResult(com.amazonaws.services.kms.model.CreateKeyResult) KMSEncryptionMaterialsProvider(com.amazonaws.services.s3.model.KMSEncryptionMaterialsProvider) CreateKeyRequest(com.amazonaws.services.kms.model.CreateKeyRequest) CryptoConfigurationV2(com.amazonaws.services.s3.model.CryptoConfigurationV2) AWSKMS(com.amazonaws.services.kms.AWSKMS)

Example 2 with CreateKeyRequest

use of com.amazonaws.services.kms.model.CreateKeyRequest in project aws-doc-sdk-examples by awsdocs.

the class CreateCustomerMasterKey method main.

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());
}
Also used : CreateKeyResult(com.amazonaws.services.kms.model.CreateKeyResult) CreateKeyRequest(com.amazonaws.services.kms.model.CreateKeyRequest) AWSKMS(com.amazonaws.services.kms.AWSKMS)

Aggregations

AWSKMS (com.amazonaws.services.kms.AWSKMS)2 CreateKeyRequest (com.amazonaws.services.kms.model.CreateKeyRequest)2 CreateKeyResult (com.amazonaws.services.kms.model.CreateKeyResult)2 ScheduleKeyDeletionRequest (com.amazonaws.services.kms.model.ScheduleKeyDeletionRequest)1 AmazonS3EncryptionV2 (com.amazonaws.services.s3.AmazonS3EncryptionV2)1 CryptoConfigurationV2 (com.amazonaws.services.s3.model.CryptoConfigurationV2)1 KMSEncryptionMaterialsProvider (com.amazonaws.services.s3.model.KMSEncryptionMaterialsProvider)1