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
13
3
14
4
package com .amazonaws .crypto .examples ;
15
5
@@ -53,7 +43,7 @@ public class FileStreamingDefaults {
53
43
* @param sourcePlaintextFile Plaintext file to encrypt
54
44
*/
55
45
public static void run (final AwsKmsCmkId awsKmsCmk , final File sourcePlaintextFile ) throws IOException {
56
- // Instantiate the SDK
46
+ // Instantiate the AWS Encryption SDK
57
47
final AwsCrypto awsEncryptionSdk = new AwsCrypto ();
58
48
59
49
// 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
63
53
encryptedFile .deleteOnExit ();
64
54
decryptedFile .deleteOnExit ();
65
55
66
- // Prepare your encryption context
56
+ // Prepare your encryption context.
67
57
// https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
68
58
final Map <String , String > encryptionContext = new HashMap <>();
69
59
encryptionContext .put ("encryption" , "context" );
@@ -84,7 +74,7 @@ public static void run(final AwsKmsCmkId awsKmsCmk, final File sourcePlaintextFi
84
74
.encryptionContext (encryptionContext )
85
75
.inputStream (new FileInputStream (sourcePlaintextFile )).build ())) {
86
76
87
- // Copy the encrypted data into the encrypted file.
77
+ // Encrypt the data and write the ciphertext to the encrypted file.
88
78
try (FileOutputStream out = new FileOutputStream (encryptedFile )) {
89
79
IOUtils .copy (encryptingStream , out );
90
80
}
@@ -111,7 +101,8 @@ public static void run(final AwsKmsCmkId awsKmsCmk, final File sourcePlaintextFi
111
101
assert v .equals (decryptResult .getEncryptionContext ().get (k ));
112
102
});
113
103
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.
115
106
try (FileOutputStream out = new FileOutputStream (decryptedFile )) {
116
107
IOUtils .copy (decryptingStream , out );
117
108
}
0 commit comments