3636 * <p>
3737 * Arguments:
3838 * <ol>
39- * <li>Key ARN: To find the Amazon Resource Name of your KMS customer master key (CMK),
40- * see 'Viewing Keys' at http://docs.aws.amazon.com/kms/latest/developerguide/viewing-keys.html
41- * <li>File Name
39+ * <li>Key ARN: For help finding the Amazon Resource Name (ARN) of your KMS customer master
40+ * key (CMK), see 'Viewing Keys' at http://docs.aws.amazon.com/kms/latest/developerguide/viewing-keys.html
41+ *
42+ * <li>Name of file containing plaintext data to encrypt
4243 * </ol>
4344 *
44- * AWS Key Management Service (KMS) is highly available. However, some organizations want to decrypt
45- * their data offline and independent of KMS. This sample demonstrates one way to do this.
45+ * You might use AWS Key Management Service (KMS) for most encryption and decryption operations, but
46+ * still want the option of decrypting your data offline independently of KMS. This sample
47+ * demonstrates one way to do this.
4648 *
47- * This program generates an "escrowed" RSA key pair. It stores the private key in a secure offline
48- * location, such as an offline HSM, and distributes the public key to their developers. It also
49- * creates a KMS customer master key (CMK). The organization encrypts their data with both the
50- * KMS CMK and the public key, so that either key alone could decrypt it.
49+ * The sample encrypts data under both a KMS customer master key (CMK) and an "escrowed" RSA key pair
50+ * so that either key alone can decrypt it. You might commonly use the KMS CMK for decryption. However,
51+ * at any time, you can use the private RSA key to decrypt the ciphertext independent of KMS.
52+ *
53+ * This sample uses the JCEMasterKey class to generate a RSA public-private key pair
54+ * and saves the key pair in memory. In practice, you would store the private key in a secure offline
55+ * location, such as an offline HSM, and distribute the public key to your development team.
5156 *
52- * The team usually uses the KMS CMK for decryption. However, the organization can, at any time
53- * use the private escrowed RSA key to decrypt the ciphertext independent of KMS.
5457 */
5558public class EscrowedEncryptExample {
5659 private static PublicKey publicEscrowKey ;
5760 private static PrivateKey privateEscrowKey ;
5861
5962 public static void main (final String [] args ) throws Exception {
60- // In practice, the organization would distribute the public key.
61- // For this demo, we generate a new random key for each operation.
63+ // This sample generates a new random key for each operation.
64+ // In practice, you would distribute the public key and save the private key in secure
65+ // storage.
6266 generateEscrowKeyPair ();
6367
6468 final String kmsArn = args [0 ];
@@ -71,16 +75,16 @@ public static void main(final String[] args) throws Exception {
7175 }
7276
7377 private static void standardEncrypt (final String kmsArn , final String fileName ) throws Exception {
74- // Standard practice: encrypt with the KMS CMK and the escrowed public key
78+ // Encrypt with the KMS CMK and the escrowed public key
7579 // 1. Instantiate the SDK
7680 final AwsCrypto crypto = new AwsCrypto ();
7781
7882 // 2. Instantiate a KMS master key provider
7983 final KmsMasterKeyProvider kms = new KmsMasterKeyProvider (kmsArn );
8084
81- // 3. Instantiate a JCE master key provider
82- // Because the standard user does not have access to the private
83- // escrow key, they pass in "null" for the private key parameter.
85+ // 3. Instantiate a JCE master key provider
86+ // Because the user does not have access to the private escrow key,
87+ // they pass in "null" for the private key parameter.
8488 final JceMasterKey escrowPub = JceMasterKey .getInstance (publicEscrowKey , null , "Escrow" , "Escrow" ,
8589 "RSA/ECB/OAEPWithSHA-512AndMGF1Padding" );
8690
@@ -100,16 +104,17 @@ private static void standardEncrypt(final String kmsArn, final String fileName)
100104 }
101105
102106 private static void standardDecrypt (final String kmsArn , final String fileName ) throws Exception {
103- // Standard practice: enncrypt with the KMS CMK and the escrow public key
107+ // Decrypt with the KMS CMK and the escrow public key. You can use a combined provider,
108+ // as shown here, or just the KMS master key provider.
104109
105110 // 1. Instantiate the SDK
106111 final AwsCrypto crypto = new AwsCrypto ();
107112
108113 // 2. Instantiate a KMS master key provider
109114 final KmsMasterKeyProvider kms = new KmsMasterKeyProvider (kmsArn );
110115
111- // 3. Instantiate a JCE master key provider
112- // Because the standard user does not have access to the private
116+ // 3. Instantiate a JCE master key provider
117+ // Because the user does not have access to the private
113118 // escrow key, they pass in "null" for the private key parameter.
114119 final JceMasterKey escrowPub = JceMasterKey .getInstance (publicEscrowKey , null , "Escrow" , "Escrow" ,
115120 "RSA/ECB/OAEPWithSHA-512AndMGF1Padding" );
@@ -129,14 +134,14 @@ private static void standardDecrypt(final String kmsArn, final String fileName)
129134 }
130135
131136 private static void escrowDecrypt (final String fileName ) throws Exception {
132- // The organization can decrypt the stream using only the private escrow key.
133- // This method does not call KMS.
137+ // You can decrypt the stream using only the private key.
138+ // This method does not call KMS.
134139
135140 // 1. Instantiate the SDK
136141 final AwsCrypto crypto = new AwsCrypto ();
137142
138143 // 2. Instantiate a JCE master key provider
139- // This method call uses the escrowed private key
144+ // This method call uses the escrowed private key, not null
140145 final JceMasterKey escrowPriv = JceMasterKey .getInstance (publicEscrowKey , privateEscrowKey , "Escrow" , "Escrow" ,
141146 "RSA/ECB/OAEPWithSHA-512AndMGF1Padding" );
142147
0 commit comments