Skip to content

Commit afa2651

Browse files
Updating wording
1 parent bb2a1d8 commit afa2651

8 files changed

+36
-29
lines changed

src/examples/java/com/amazonaws/crypto/examples/BasicEncryptionExample.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,17 @@ static void encryptAndDecrypt(final AwsKmsCmkId keyArn) {
7878
.keyring(keyring)
7979
.ciphertext(ciphertext).build());
8080

81-
// 6. The Keyring Trace may be inspected to verify which CMK was used for decryption.
81+
// 6. To verify the CMK that was actually used in the decrypt operation, inspect the keyring trace.
8282
if(!decryptResult.getKeyringTrace().getEntries().get(0).getKeyName().equals(keyArn.toString())) {
8383
throw new IllegalStateException("Wrong key ID!");
8484
}
8585

86-
// 7. Verify that the encryption context in the result contains the
87-
// data that we expect. The SDK can add values to the encryption context,
88-
// so there may be additional keys in the result context.
86+
// 7. To verify that the encryption context used to decrypt the data was the encryption context you expected,
87+
// examine the encryption context in the result. This helps to ensure that you decrypted the ciphertext that
88+
// you intended.
89+
//
90+
// When verifying, test that your expected encryption context is a subset of the actual encryption context,
91+
// not an exact match. The Encryption SDK adds the signing key to the encryption context when appropriate.
8992
assert decryptResult.getEncryptionContext().get("ExampleContextKey").equals("ExampleContextValue");
9093

9194
// 8. Verify that the decrypted plaintext matches the original plaintext

src/examples/java/com/amazonaws/crypto/examples/FileStreamingExample.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void encryptAndDecrypt(final File srcFile, final File encryptedFile, fina
6464
final AwsCrypto crypto = new AwsCrypto();
6565

6666
// 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.
6868
final SecretKey cryptoKey = generateEncryptKey();
6969

7070
// 3. Instantiate a RawAesKeyring using the random key
@@ -104,11 +104,12 @@ static void encryptAndDecrypt(final File srcFile, final File encryptedFile, fina
104104
.keyring(keyring)
105105
.inputStream(new FileInputStream(encryptedFile)).build())) {
106106

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"));
112113

113114
// 9. Copy the plaintext data to a file
114115
try (FileOutputStream out = new FileOutputStream(decryptedFile)) {
@@ -122,7 +123,7 @@ static void encryptAndDecrypt(final File srcFile, final File encryptedFile, fina
122123

123124
/**
124125
* 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.
126127
*/
127128
private static SecretKey generateEncryptKey() {
128129
SecureRandom rnd = new SecureRandom();

src/examples/java/com/amazonaws/crypto/examples/RawAesKeyringExample.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void encryptAndDecrypt() {
5050
final SecretKey cryptoKey = generateEncryptKey();
5151

5252
// 3. Instantiate a Raw AES Keyring with the encryption key
53-
final Keyring keyring = StandardKeyrings.rawAes()
53+
final Keyring keyring = StandardKeyrings.rawAesBuilder()
5454
.keyNamespace("ExampleKeyNamespace")
5555
.keyName("ExampleKeyName")
5656
.wrappingKey(cryptoKey).build();
@@ -76,9 +76,11 @@ static void encryptAndDecrypt() {
7676
.keyring(keyring)
7777
.ciphertext(ciphertext).build());
7878

79-
// 7. Verify that the encryption context in the result contains the
80-
// data that we expect. The SDK can add values to the encryption context,
81-
// so there may be additional keys in the result context.
79+
// 7. Verify that the encryption context that was used to decrypt the data is the one that you expect.
80+
// This helps to ensure that the ciphertext that you decrypted was the one that you intended.
81+
//
82+
// When verifying, test that your expected encryption context is a subset of the actual encryption context,
83+
// not an exact match. When appropriate, the Encryption SDK adds the signing key to the encryption context.
8284
assert decryptResult.getEncryptionContext().get("ExampleContextKey").equals("ExampleContextValue");
8385

8486
// 8. Verify that the decrypted plaintext matches the original plaintext

src/examples/java/com/amazonaws/crypto/examples/RawRsaKeyringDecryptExample.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static byte[] decrypt(byte[] ciphertext, KeyPair keyPair) {
3232
final AwsCrypto crypto = new AwsCrypto();
3333

3434
// 2. Instantiate a Raw RSA Keyring with the private key
35-
final Keyring keyring = StandardKeyrings.rawRsa()
35+
final Keyring keyring = StandardKeyrings.rawRsaBuilder()
3636
.keyNamespace("ExampleKeyNamespace")
3737
.keyName("ExampleKeyName")
3838
.wrappingAlgorithm("RSA/ECB/OAEPWithSHA-512AndMGF1Padding")
@@ -43,9 +43,11 @@ public static byte[] decrypt(byte[] ciphertext, KeyPair keyPair) {
4343
.keyring(keyring)
4444
.ciphertext(ciphertext).build());
4545

46-
// 4. Verify that the encryption context in the result contains the
47-
// data that we expect. The SDK can add values to the encryption context,
48-
// so there may be additional keys in the result context.
46+
// 4. Verify that the encryption context that was used to decrypt the data is the one that you expect.
47+
// This helps to ensure that the ciphertext that you decrypted was the one that you intended.
48+
//
49+
// When verifying, test that your expected encryption context is a subset of the actual encryption context,
50+
// not an exact match. When appropriate, the Encryption SDK adds the signing key to the encryption context.
4951
assert decryptResult.getEncryptionContext().get("ExampleContextKey").equals("ExampleContextValue");
5052

5153
// 5. Return the decrypted byte array result

src/examples/java/com/amazonaws/crypto/examples/RawRsaKeyringEncryptExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static byte[] encrypt(PublicKey publicKey) {
3636
final AwsCrypto crypto = new AwsCrypto();
3737

3838
// 2. Instantiate a Raw RSA Keyring with the public key
39-
final Keyring keyring = StandardKeyrings.rawRsa()
39+
final Keyring keyring = StandardKeyrings.rawRsaBuilder()
4040
.keyNamespace("ExampleKeyNamespace")
4141
.keyName("ExampleKeyName")
4242
.wrappingAlgorithm("RSA/ECB/OAEPWithSHA-512AndMGF1Padding")

src/examples/java/com/amazonaws/crypto/examples/datakeycaching/LambdaDecryptAndWriteExample.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ public class LambdaDecryptAndWriteExample implements RequestHandler<KinesisEvent
4545
private final Table table_;
4646

4747
/**
48-
* Because the cache is used only for decryption, the code doesn't set
49-
* the max bytes or max message security thresholds that are enforced
50-
* only on on data keys used for encryption.
48+
* This code doesn't set the max bytes or max message security thresholds that are enforced
49+
* only on data keys used for encryption.
5150
*
5251
* @param cmkArn The AWS KMS customer master key to use for decryption
53-
* @param tableName The DynamoDB table name to store decrypted messages in
52+
* @param tableName The name of the DynamoDB table name that stores decrypted messages
5453
*/
5554
public LambdaDecryptAndWriteExample(final String cmkArn, final String tableName) {
5655
cachingMaterialsManager_ = CachingCryptoMaterialsManager.newBuilder()

src/examples/java/com/amazonaws/crypto/examples/datakeycaching/MultiRegionRecordPusherExample.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public MultiRegionRecordPusherExample(final Region[] regions, final String kmsAl
6363

6464
final DefaultAWSCredentialsProviderChain credentialsProvider = new DefaultAWSCredentialsProviderChain();
6565

66-
// Build AwsKmsKeyring and AmazonKinesisClient objects for each target region
66+
// Build AwsKmsKeyring and AmazonKinesisClient objects for each target Region
6767
final List<Keyring> keyrings = new ArrayList<>();
6868

6969
for (Region region : regions) {
@@ -72,16 +72,16 @@ public MultiRegionRecordPusherExample(final Region[] regions, final String kmsAl
7272
.withRegion(region.getName())
7373
.build());
7474

75-
keyrings.add(StandardKeyrings.awsKms()
75+
keyrings.add(StandardKeyrings.awsKmsBuilder()
7676
.awsKmsClientSupplier(AwsKmsClientSupplier.builder()
7777
.credentialsProvider(credentialsProvider)
7878
.allowedRegions(Collections.singleton(region.getName()))
7979
.build())
8080
.generatorKeyId(AwsKmsCmkId.fromString(kmsAliasName)).build());
8181
}
8282

83-
// Collect keyrings into single multi keyring and add cache. The keyring for the
84-
// first region will be used to generate a data key.
83+
// Collect keyrings into a single multi-keyring and add cache. In this example, the keyring for the
84+
// first region is used as the generatorKeyring to generate a data key.
8585
final List<Keyring> childrenKeyrings = keyrings.size() > 1 ? keyrings.subList(1, keyrings.size()) : emptyList();
8686
final Keyring keyring = StandardKeyrings.multi(keyrings.get(0), childrenKeyrings);
8787

src/test/java/com/amazonaws/crypto/examples/RawRsaKeyringEncryptExampleTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void testEncrypt() throws Exception {
3434

3535
byte[] ciphertext = RawRsaKeyringEncryptExample.encrypt(keyPair.getPublic());
3636

37-
final Keyring keyring = StandardKeyrings.rawRsa()
37+
final Keyring keyring = StandardKeyrings.rawRsaBuilder()
3838
.keyNamespace("ExampleKeyNamespace")
3939
.keyName("ExampleKeyName")
4040
.privateKey(keyPair.getPrivate())

0 commit comments

Comments
 (0)