@@ -99,16 +99,16 @@ public class StringExample {
9999
100100 // Set up the master key provider
101101 final KmsMasterKeyProvider prov = KmsMasterKeyProvider . builder(). buildStrict(keyArn);
102-
103- // Set up encryption context
102+
103+ // Set up the encryption context
104104 final Map<String , String > context = Collections . singletonMap(" ExampleContextKey" , " ExampleContextValue" );
105105
106106 // Encrypt the data
107107 //
108108 // NOTE: Encrypted data should have associated encryption context
109- // to protect integrity. For this example, just use a placeholder
110- // value. For more information about encryption context, see
111- // https://amzn.to/1nSbe9X (blogs. aws.amazon.com)
109+ // to protect its integrity. This example uses placeholder values.
110+ // For more information about encryption context, see
111+ // https://docs. aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
112112 final CryptoResult<byte[], KmsMasterKey > encryptResult = crypto. encryptData(prov, data. getBytes(StandardCharsets . UTF_8 ), context);
113113 final byte [] ciphertext = encryptResult. getResult();
114114 System . out. println(" Ciphertext: " + Arrays . toString(ciphertext));
@@ -121,17 +121,17 @@ public class StringExample {
121121 throw new IllegalStateException (" Wrong key id!" );
122122 }
123123
124- // The SDK may add information to the encryption context, so check to
125- // ensure all of the values are present
124+ // The AWS Encryption SDK may add information to the encryption context, so check to
125+ // ensure all of the values that you specified when encrypting are included in the returned encryption context.
126126 if (! context. entrySet(). stream
127127 .allMatch( e - > e. getValue(). equals(decryptResult. getEncryptionContext(). get(e. getKey())))) {
128128 throw new IllegalStateException (" Wrong Encryption Context!" );
129129 }
130130
131131 assert Arrays . equals(decryptResult. getResult(), data. getBytes(StandardCharsets . UTF_8 ));
132132
133- // The data is correct, so output it.
134- System . out. println(" Decrypted: " + Arrays . toString (decryptResult. getResult()));
133+ // The data is correct, so return it.
134+ System . out. println(" Decrypted: " + new String (decryptResult. getResult(), StandardCharsets . UTF_8 ));
135135 }
136136}
137137```
0 commit comments