AWS Code Sample

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above. demonstrates how to encrypt data keys

package aws.example.kms; import; import; import; import java.nio.ByteBuffer; public class EncryptDataKey { public static void main(String[] args) { AWSKMS kmsClient = AWSKMSClientBuilder.standard().build(); // Encrypt a data key // // Replace the following fictitious CMK ARN with a valid CMK ID or ARN String keyId = "1234abcd-12ab-34cd-56ef-1234567890ab"; ByteBuffer plaintext = ByteBuffer.wrap(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}); EncryptRequest req = new EncryptRequest().withKeyId(keyId).withPlaintext(plaintext); ByteBuffer ciphertext = kmsClient.encrypt(req).getCiphertextBlob(); } }

Sample Details

Service: kms

Last tested: 2019-04-08

Author: AWS

Type: full-example

On this page: