Skip to content

Commit 2ad02ff

Browse files
Updated wording and copyright notice
1 parent 81091ae commit 2ad02ff

23 files changed

+108
-303
lines changed

src/examples/README.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,31 @@ you need to describe how you want the library to protect your data keys.
2121
You can do this using
2222
[keyrings](#keyrings) or [cryptographic materials managers](#cryptographic-materials-managers),
2323
or using [master key providers](#master-key-providers).
24-
These examples will show you how.
24+
These examples will show you how yo use the configuration tools that we include for you
25+
as well as how to create some of your own. We start with AWS KMS examples, then show
26+
how to use other wrapping keys.
27+
28+
* Using AWS Key Management Service (AWS KMS)
29+
* How to use a single AWS KMS CMK
30+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/awskms/SingleCmk.java)
31+
* How to use multiple AWS KMS CMKs in different regions
32+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/awskms/MultipleRegions.java)
33+
* How to decrypt when you don't know the CMK
34+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/awskms/DiscoveryDecrypt.java)
35+
* How to decrypt within a region
36+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/awskms/DiscoveryDecryptInRegionOnly.java)
37+
* How to decrypt with a preferred region but failover to others
38+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/awskms/DiscoveryDecryptWithPreferredRegions.java)
39+
* Using raw wrapping keys
40+
* How to use a raw AES wrapping key
41+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/rawaes/RawAes.java)
42+
* How to use a raw RSA wrapping key
43+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/rawrsa/RawRsa.java)
44+
* How to encrypt with a raw RSA public key wrapping key without access to the private key
45+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/rawrsa/PublicPrivateKeySeparate.java)
46+
* Combining wrapping keys
47+
* How to combine AWS KMS with an offline escrow key
48+
* [with keyrings](./java/com/amazonaws/crypto/examples/keyring/multi/AwsKmsWithEscrow.java)
2549

2650
### Keyrings
2751

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

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
/*
2-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except
5-
* in compliance with the License. A copy of the License is located at
6-
*
7-
* http://aws.amazon.com/apache2.0
8-
*
9-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
10-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11-
* specific language governing permissions and limitations under the License.
12-
*/
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
133

144
package com.amazonaws.crypto.examples;
155

@@ -53,7 +43,7 @@ public class FileStreamingDefaults {
5343
* @param sourcePlaintextFile Plaintext file to encrypt
5444
*/
5545
public static void run(final AwsKmsCmkId awsKmsCmk, final File sourcePlaintextFile) throws IOException {
56-
// Instantiate the SDK
46+
// Instantiate the AWS Encryption SDK
5747
final AwsCrypto awsEncryptionSdk = new AwsCrypto();
5848

5949
// We assume that you can also write to the directory containing the plaintext file,
@@ -63,7 +53,7 @@ public static void run(final AwsKmsCmkId awsKmsCmk, final File sourcePlaintextFi
6353
encryptedFile.deleteOnExit();
6454
decryptedFile.deleteOnExit();
6555

66-
// Prepare your encryption context
56+
// Prepare your encryption context.
6757
// https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
6858
final Map<String, String> encryptionContext = new HashMap<>();
6959
encryptionContext.put("encryption", "context");
@@ -84,7 +74,7 @@ public static void run(final AwsKmsCmkId awsKmsCmk, final File sourcePlaintextFi
8474
.encryptionContext(encryptionContext)
8575
.inputStream(new FileInputStream(sourcePlaintextFile)).build())) {
8676

87-
// Copy the encrypted data into the encrypted file.
77+
// Encrypt the data and write the ciphertext to the encrypted file.
8878
try (FileOutputStream out = new FileOutputStream(encryptedFile)) {
8979
IOUtils.copy(encryptingStream, out);
9080
}
@@ -111,7 +101,8 @@ public static void run(final AwsKmsCmkId awsKmsCmk, final File sourcePlaintextFi
111101
assert v.equals(decryptResult.getEncryptionContext().get(k));
112102
});
113103

114-
// Copy the plaintext data to a file
104+
// Now that we are more confident that we will decrypt the right message,
105+
// we can start decrypting.
115106
try (FileOutputStream out = new FileOutputStream(decryptedFile)) {
116107
IOUtils.copy(decryptingStream, out);
117108
}

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

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
/*
2-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except
5-
* in compliance with the License. A copy of the License is located at
6-
*
7-
* http://aws.amazon.com/apache2.0
8-
*
9-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
10-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11-
* specific language governing permissions and limitations under the License.
12-
*/
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
133

144
package com.amazonaws.crypto.examples;
155

@@ -50,10 +40,10 @@ public class InMemoryStreamingDefaults {
5040
* @param sourcePlaintext Plaintext to encrypt
5141
*/
5242
public static void run(final AwsKmsCmkId awsKmsCmk, final byte[] sourcePlaintext) throws IOException {
53-
// Instantiate the SDK
43+
// Instantiate the AWS Encryption SDK
5444
final AwsCrypto awsEncryptionSdk = new AwsCrypto();
5545

56-
// Prepare your encryption context
46+
// Prepare your encryption context.
5747
// https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
5848
final Map<String, String> encryptionContext = new HashMap<>();
5949
encryptionContext.put("encryption", "context");

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

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
/*
2-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except
5-
* in compliance with the License. A copy of the License is located at
6-
*
7-
* http://aws.amazon.com/apache2.0
8-
*
9-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
10-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11-
* specific language governing permissions and limitations under the License.
12-
*/
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
133

144
package com.amazonaws.crypto.examples;
155

@@ -42,10 +32,10 @@ public class OneStepDefaults {
4232
* @param sourcePlaintext Plaintext to encrypt
4333
*/
4434
public static void run(final AwsKmsCmkId awsKmsCmk, final byte[] sourcePlaintext) {
45-
// Instantiate the SDK
35+
// Instantiate the AWS Encryption SDK
4636
final AwsCrypto awsEncryptionSdk = new AwsCrypto();
4737

48-
// Prepare your encryption context
38+
// Prepare your encryption context.
4939
// https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
5040
final Map<String, String> encryptionContext = new HashMap<>();
5141
encryptionContext.put("encryption", "context");

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

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
/*
2-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except
5-
* in compliance with the License. A copy of the License is located at
6-
*
7-
* http://aws.amazon.com/apache2.0
8-
*
9-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
10-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11-
* specific language governing permissions and limitations under the License.
12-
*/
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
133

144
package com.amazonaws.crypto.examples;
155

@@ -55,11 +45,11 @@ public class OneStepUnsigned {
5545
* @param sourcePlaintext Plaintext to encrypt
5646
*/
5747
public static void run(final AwsKmsCmkId awsKmsCmk, final byte[] sourcePlaintext) {
58-
// Instantiate the SDK and specify the algorithm suite that we want to use.
48+
// Instantiate the AWS Encryption SDK and specify the algorithm suite that we want to use.
5949
final AwsCrypto awsEncryptionSdk = new AwsCrypto();
6050
awsEncryptionSdk.setEncryptionAlgorithm(CryptoAlgorithm.ALG_AES_256_GCM_IV12_TAG16_HKDF_SHA256);
6151

62-
// Prepare your encryption context
52+
// Prepare your encryption context.
6353
// https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
6454
final Map<String, String> encryptionContext = new HashMap<>();
6555
encryptionContext.put("encryption", "context");

src/examples/java/com/amazonaws/crypto/examples/keyring/awskms/CustomClientSupplier.java

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
/*
2-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except
5-
* in compliance with the License. A copy of the License is located at
6-
*
7-
* http://aws.amazon.com/apache2.0
8-
*
9-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
10-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11-
* specific language governing permissions and limitations under the License.
12-
*/
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
133

144
package com.amazonaws.crypto.examples.keyring.awskms;
155

@@ -95,10 +85,10 @@ public AWSKMS getClient(String regionId) {
9585
* @param sourcePlaintext Plaintext to encrypt
9686
*/
9787
public static void run(final AwsKmsCmkId awsKmsCmk, final byte[] sourcePlaintext) {
98-
// Instantiate the SDK
88+
// Instantiate the AWS Encryption SDK
9989
final AwsCrypto awsEncryptionSdk = new AwsCrypto();
10090

101-
// Prepare your encryption context
91+
// Prepare your encryption context.
10292
// https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
10393
final Map<String, String> encryptionContext = new HashMap<>();
10494
encryptionContext.put("encryption", "context");

src/examples/java/com/amazonaws/crypto/examples/keyring/awskms/CustomKmsClientConfig.java

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
/*
2-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except
5-
* in compliance with the License. A copy of the License is located at
6-
*
7-
* http://aws.amazon.com/apache2.0
8-
*
9-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
10-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11-
* specific language governing permissions and limitations under the License.
12-
*/
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
133

144
package com.amazonaws.crypto.examples.keyring.awskms;
155

@@ -58,10 +48,10 @@ public class CustomKmsClientConfig {
5848
* @param sourcePlaintext Plaintext to encrypt
5949
*/
6050
public static void run(final AwsKmsCmkId awsKmsCmk, final byte[] sourcePlaintext) {
61-
// Instantiate the SDK
51+
// Instantiate the AWS Encryption SDK
6252
final AwsCrypto awsEncryptionSdk = new AwsCrypto();
6353

64-
// Prepare your encryption context
54+
// Prepare your encryption context.
6555
// https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
6656
final Map<String, String> encryptionContext = new HashMap<>();
6757
encryptionContext.put("encryption", "context");

src/examples/java/com/amazonaws/crypto/examples/keyring/awskms/DiscoveryDecrypt.java

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
/*
2-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except
5-
* in compliance with the License. A copy of the License is located at
6-
*
7-
* http://aws.amazon.com/apache2.0
8-
*
9-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
10-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11-
* specific language governing permissions and limitations under the License.
12-
*/
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
133

144
package com.amazonaws.crypto.examples.keyring.awskms;
155

@@ -58,10 +48,10 @@ public class DiscoveryDecrypt {
5848
* @param sourcePlaintext Plaintext to encrypt
5949
*/
6050
public static void run(final AwsKmsCmkId awsKmsCmk, final byte[] sourcePlaintext) {
61-
// Instantiate the SDK
51+
// Instantiate the AWS Encryption SDK
6252
final AwsCrypto awsEncryptionSdk = new AwsCrypto();
6353

64-
// Prepare your encryption context
54+
// Prepare your encryption context.
6555
// https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
6656
final Map<String, String> encryptionContext = new HashMap<>();
6757
encryptionContext.put("encryption", "context");

src/examples/java/com/amazonaws/crypto/examples/keyring/awskms/DiscoveryDecryptInRegionOnly.java

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
/*
2-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except
5-
* in compliance with the License. A copy of the License is located at
6-
*
7-
* http://aws.amazon.com/apache2.0
8-
*
9-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
10-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11-
* specific language governing permissions and limitations under the License.
12-
*/
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
133

144
package com.amazonaws.crypto.examples.keyring.awskms;
155

@@ -65,10 +55,10 @@ public class DiscoveryDecryptInRegionOnly {
6555
* @param sourcePlaintext Plaintext to encrypt
6656
*/
6757
public static void run(final AwsKmsCmkId awsKmsCmk, final byte[] sourcePlaintext) {
68-
// Instantiate the SDK
58+
// Instantiate the AWS Encryption SDK
6959
final AwsCrypto awsEncryptionSdk = new AwsCrypto();
7060

71-
// Prepare your encryption context
61+
// Prepare your encryption context.
7262
// https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
7363
final Map<String, String> encryptionContext = new HashMap<>();
7464
encryptionContext.put("encryption", "context");

src/examples/java/com/amazonaws/crypto/examples/keyring/awskms/DiscoveryDecryptWithPreferredRegions.java

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
/*
2-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except
5-
* in compliance with the License. A copy of the License is located at
6-
*
7-
* http://aws.amazon.com/apache2.0
8-
*
9-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
10-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11-
* specific language governing permissions and limitations under the License.
12-
*/
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
133

144
package com.amazonaws.crypto.examples.keyring.awskms;
155

@@ -71,10 +61,10 @@ public class DiscoveryDecryptWithPreferredRegions {
7161
* @param sourcePlaintext Plaintext to encrypt
7262
*/
7363
public static void run(final AwsKmsCmkId awsKmsCmk, final byte[] sourcePlaintext) {
74-
// Instantiate the SDK
64+
// Instantiate the AWS Encryption SDK
7565
final AwsCrypto awsEncryptionSdk = new AwsCrypto();
7666

77-
// Prepare your encryption context
67+
// Prepare your encryption context.
7868
// https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
7969
final Map<String, String> encryptionContext = new HashMap<>();
8070
encryptionContext.put("encryption", "context");

src/examples/java/com/amazonaws/crypto/examples/keyring/awskms/MultipleRegions.java

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
/*
2-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except
5-
* in compliance with the License. A copy of the License is located at
6-
*
7-
* http://aws.amazon.com/apache2.0
8-
*
9-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
10-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11-
* specific language governing permissions and limitations under the License.
12-
*/
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
133

144
package com.amazonaws.crypto.examples.keyring.awskms;
155

@@ -54,10 +44,10 @@ public class MultipleRegions {
5444
* @param sourcePlaintext Plaintext to encrypt
5545
*/
5646
public static void run(final AwsKmsCmkId awsKmsGeneratorCmk, final List<AwsKmsCmkId> awsKmsAdditionalCmks, byte[] sourcePlaintext) {
57-
// Instantiate the SDK
47+
// Instantiate the AWS Encryption SDK
5848
final AwsCrypto awsEncryptionSdk = new AwsCrypto();
5949

60-
// Prepare your encryption context
50+
// Prepare your encryption context.
6151
// https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
6252
final Map<String, String> encryptionContext = new HashMap<>();
6353
encryptionContext.put("encryption", "context");

src/examples/java/com/amazonaws/crypto/examples/keyring/awskms/SingleCmk.java

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
/*
2-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except
5-
* in compliance with the License. A copy of the License is located at
6-
*
7-
* http://aws.amazon.com/apache2.0
8-
*
9-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
10-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11-
* specific language governing permissions and limitations under the License.
12-
*/
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
133

144
package com.amazonaws.crypto.examples.keyring.awskms;
155

@@ -51,10 +41,10 @@ public class SingleCmk {
5141
* @param sourcePlaintext Plaintext to encrypt
5242
*/
5343
public static void run(final AwsKmsCmkId awsKmsCmk, final byte[] sourcePlaintext) {
54-
// Instantiate the SDK
44+
// Instantiate the AWS Encryption SDK
5545
final AwsCrypto awsEncryptionSdk = new AwsCrypto();
5646

57-
// Prepare your encryption context
47+
// Prepare your encryption context.
5848
// https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
5949
final Map<String, String> encryptionContext = new HashMap<>();
6050
encryptionContext.put("encryption", "context");

0 commit comments

Comments
 (0)