@@ -99,16 +99,16 @@ public class StringExample {
99
99
100
100
// Set up the master key provider
101
101
final KmsMasterKeyProvider prov = KmsMasterKeyProvider . builder(). buildStrict(keyArn);
102
-
103
- // Set up encryption context
102
+
103
+ // Set up the encryption context
104
104
final Map<String , String > context = Collections . singletonMap(" ExampleContextKey" , " ExampleContextValue" );
105
105
106
106
// Encrypt the data
107
107
//
108
108
// 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
112
112
final CryptoResult<byte[], KmsMasterKey > encryptResult = crypto. encryptData(prov, data. getBytes(StandardCharsets . UTF_8 ), context);
113
113
final byte [] ciphertext = encryptResult. getResult();
114
114
System . out. println(" Ciphertext: " + Arrays . toString(ciphertext));
@@ -121,17 +121,17 @@ public class StringExample {
121
121
throw new IllegalStateException (" Wrong key id!" );
122
122
}
123
123
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.
126
126
if (! context. entrySet(). stream
127
127
.allMatch( e - > e. getValue(). equals(decryptResult. getEncryptionContext(). get(e. getKey())))) {
128
128
throw new IllegalStateException (" Wrong Encryption Context!" );
129
129
}
130
130
131
131
assert Arrays . equals(decryptResult. getResult(), data. getBytes(StandardCharsets . UTF_8 ));
132
132
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 ));
135
135
}
136
136
}
137
137
```
0 commit comments