@@ -64,7 +64,7 @@ static void encryptAndDecrypt(final File srcFile, final File encryptedFile, fina
64
64
final AwsCrypto crypto = new AwsCrypto ();
65
65
66
66
// 2. Get an encryption key. In this example, we generate a random key.
67
- // In practice, you would get a key from an existing key store
67
+ // In practice, you would get a key from an existing key store.
68
68
final SecretKey cryptoKey = generateEncryptKey ();
69
69
70
70
// 3. Instantiate a RawAesKeyring using the random key
@@ -104,11 +104,12 @@ static void encryptAndDecrypt(final File srcFile, final File encryptedFile, fina
104
104
.keyring (keyring )
105
105
.inputStream (new FileInputStream (encryptedFile )).build ())) {
106
106
107
- // 8. Verify that the encryption context in the result contains the
108
- // encryption context supplied to the createEncryptingStream method.
109
- if (!"FileStreaming" .equals (decryptingStream .getAwsCryptoResult ().getEncryptionContext ().get ("Example" ))) {
110
- throw new IllegalStateException ("Bad encryption context" );
111
- }
107
+ // 8. Verify that the encryption context that was used to decrypt the data is the one that you expect.
108
+ // This helps to ensure that the ciphertext that you decrypted was the one that you intended.
109
+ //
110
+ // When verifying, test that your expected encryption context is a subset of the actual encryption context,
111
+ // not an exact match. When appropriate, the Encryption SDK adds the signing key to the encryption context.
112
+ assert "FileStreaming" .equals (decryptingStream .getAwsCryptoResult ().getEncryptionContext ().get ("Example" ));
112
113
113
114
// 9. Copy the plaintext data to a file
114
115
try (FileOutputStream out = new FileOutputStream (decryptedFile )) {
@@ -122,7 +123,7 @@ static void encryptAndDecrypt(final File srcFile, final File encryptedFile, fina
122
123
123
124
/**
124
125
* In practice, this key would be saved in a secure location.
125
- * For this demo , we generate a new random key for each operation.
126
+ * In this example , we generate a new random key for each operation.
126
127
*/
127
128
private static SecretKey generateEncryptKey () {
128
129
SecureRandom rnd = new SecureRandom ();
0 commit comments