14
14
package com .amazonaws .crypto .examples ;
15
15
16
16
import com .amazonaws .encryptionsdk .AwsCrypto ;
17
- import com .amazonaws .encryptionsdk .AwsCrypto .AwsCryptoConfig ;
17
+ import com .amazonaws .encryptionsdk .DecryptRequest ;
18
+ import com .amazonaws .encryptionsdk .EncryptRequest ;
18
19
import com .amazonaws .encryptionsdk .keyrings .Keyring ;
19
20
import com .amazonaws .encryptionsdk .keyrings .StandardKeyrings ;
20
21
import com .amazonaws .encryptionsdk .kms .KmsClientSupplier ;
48
49
* so that either key alone can decrypt it. You might commonly use the KMS CMK for decryption. However,
49
50
* at any time, you can use the private RSA key to decrypt the ciphertext independent of KMS.
50
51
*
51
- * This sample uses an RawRsaKeyring to generate a RSA public-private key pair
52
+ * This sample uses a RawRsaKeyring to generate a RSA public-private key pair
52
53
* and saves the key pair in memory. In practice, you would store the private key in a secure offline
53
54
* location, such as an offline HSM, and distribute the public key to your development team.
54
55
*
@@ -105,15 +106,13 @@ private static byte[] standardEncrypt(final String kmsArn, final PublicKey publi
105
106
// 5. Combine the providers into a single MultiKeyring
106
107
final Keyring keyring = StandardKeyrings .multi (kmsKeyring , rsaKeyring );
107
108
108
- // 6. Instantiate the AwsCryptoConfig input to AwsCrypto with the keyring
109
+ // 6. Encrypt the data with the keyring.
109
110
// To simplify the code, we omit the encryption context. Production code should always
110
111
// use an encryption context. For an example, see the other SDK samples.
111
- final AwsCryptoConfig config = AwsCryptoConfig .builder ()
112
+ return crypto . encrypt ( EncryptRequest .builder ()
112
113
.keyring (keyring )
113
- .build ();
114
-
115
- // 7. Encrypt the data
116
- return crypto .encryptData (config , EXAMPLE_DATA ).getResult ();
114
+ .plaintext (EXAMPLE_DATA ).build ())
115
+ .getResult ();
117
116
}
118
117
119
118
private static byte [] standardDecrypt (final String kmsArn , final byte [] cipherText ) {
@@ -131,15 +130,12 @@ private static byte[] standardDecrypt(final String kmsArn, final byte[] cipherTe
131
130
// key with, but those can be supplied as necessary.
132
131
final Keyring kmsKeyring = StandardKeyrings .kms (clientSupplier , emptyList (), emptyList (), kmsArn );
133
132
134
- // 4. Instantiate the AwsCryptoConfig input to AwsCrypto with the keyring
133
+ // 4. Decrypt the data with the keyring.
135
134
// To simplify the code, we omit the encryption context. Production code should always
136
135
// use an encryption context. For an example, see the other SDK samples.
137
- final AwsCryptoConfig config = AwsCryptoConfig .builder ()
136
+ return crypto . decrypt ( DecryptRequest .builder ()
138
137
.keyring (kmsKeyring )
139
- .build ();
140
-
141
- // 5. Decrypt the data
142
- return crypto .decryptData (config , cipherText ).getResult ();
138
+ .ciphertext (cipherText ).build ()).getResult ();
143
139
}
144
140
145
141
private static byte [] escrowDecrypt (final byte [] cipherText , final PublicKey publicEscrowKey , final PrivateKey privateEscrowKey ) {
@@ -153,15 +149,12 @@ private static byte[] escrowDecrypt(final byte[] cipherText, final PublicKey pub
153
149
final Keyring rsaKeyring = StandardKeyrings .rawRsa ("Escrow" , "Escrow" ,
154
150
publicEscrowKey , privateEscrowKey , "RSA/ECB/OAEPWithSHA-512AndMGF1Padding" );
155
151
156
- // 3. Instantiate the AwsCryptoConfig input to AwsCrypto with the keyring
152
+ // 3. Decrypt the data with the keyring
157
153
// To simplify the code, we omit the encryption context. Production code should always
158
154
// use an encryption context. For an example, see the other SDK samples.
159
- final AwsCryptoConfig config = AwsCryptoConfig .builder ()
155
+ return crypto . decrypt ( DecryptRequest .builder ()
160
156
.keyring (rsaKeyring )
161
- .build ();
162
-
163
- // 4. Decrypt the data
164
- return crypto .decryptData (config , cipherText ).getResult ();
157
+ .ciphertext (cipherText ).build ()).getResult ();
165
158
}
166
159
167
160
private static KeyPair generateEscrowKeyPair () throws GeneralSecurityException {
0 commit comments