@@ -54,95 +54,13 @@ You can get the latest release from Maven:
54
54
<dependency >
55
55
<groupId >com.amazonaws</groupId >
56
56
<artifactId >aws-encryption-sdk-java</artifactId >
57
- <version >1.7.0 </version >
57
+ <version >1.6.1 </version >
58
58
</dependency >
59
59
```
60
60
61
- ### Get Started
62
-
63
- The following code sample demonstrates how to get started:
64
-
65
- 1 . Instantiate the SDK.
66
- 2 . Setup a KMS keyring.
67
- 3 . Encrypt and decrypt data.
68
-
69
- ``` java
70
- // This sample code encrypts and then decrypts data using an AWS Key Management Service (AWS KMS) customer master key (CMK).
71
- package com.amazonaws.crypto.examples ;
72
-
73
- import java.nio.charset.StandardCharsets ;
74
- import java.util.Arrays ;
75
- import java.util.Collections ;
76
- import java.util.Map ;
77
-
78
- import com.amazonaws.encryptionsdk.AwsCrypto ;
79
- import com.amazonaws.encryptionsdk.AwsCryptoResult ;
80
- import com.amazonaws.encryptionsdk.DecryptRequest ;
81
- import com.amazonaws.encryptionsdk.EncryptRequest ;
82
- import com.amazonaws.encryptionsdk.keyrings.Keyring ;
83
- import com.amazonaws.encryptionsdk.keyrings.StandardKeyrings ;
84
- import com.amazonaws.encryptionsdk.kms.AwsKmsCmkId ;
85
-
86
- public class BasicEncryptionExample {
87
-
88
- private static final byte [] EXAMPLE_DATA = " Hello World" . getBytes (StandardCharsets .UTF_8 );
89
-
90
- public static void main (final String [] args ) {
91
- encryptAndDecrypt(AwsKmsCmkId . fromString(args[0 ]));
92
- }
93
-
94
- static void encryptAndDecrypt (final AwsKmsCmkId keyArn ) {
95
- // 1. Instantiate the SDK
96
- final AwsCrypto crypto = new AwsCrypto ();
97
-
98
- // 2. Instantiate a KMS keyring. Supply the key ARN for the generator key that generates a
99
- // data key. While using a key ARN is a best practice, for encryption operations you can also
100
- // use an alias name or alias ARN.
101
- final Keyring keyring = StandardKeyrings . awsKms(keyArn);
102
-
103
- // 3. Create an encryption context
104
- //
105
- // Most encrypted data should have an associated encryption context
106
- // to protect integrity. This sample uses placeholder values.
107
- //
108
- // For more information see: https://amzn.to/1nSbe9X (blogs.aws.amazon.com)
109
- final Map<String , String > encryptionContext = Collections . singletonMap(" Example" , " String" );
110
-
111
- // 4. Encrypt the data with the keyring and encryption context
112
- final AwsCryptoResult<byte[]> encryptResult = crypto. encrypt(
113
- EncryptRequest . builder()
114
- .keyring(keyring)
115
- .encryptionContext(encryptionContext)
116
- .plaintext(EXAMPLE_DATA ). build());
117
- final byte [] ciphertext = encryptResult. getResult();
118
-
119
- // 5. Decrypt the data. You can use the same keyring to encrypt and decrypt, but for decryption
120
- // the key IDs must be in the key ARN format.
121
- final AwsCryptoResult<byte[]> decryptResult = crypto. decrypt(
122
- DecryptRequest . builder()
123
- .keyring(keyring)
124
- .ciphertext(ciphertext). build());
125
-
126
- // 6. To verify the CMK that was actually used in the decrypt operation, inspect the keyring trace.
127
- if (! decryptResult. getKeyringTrace(). getEntries(). get(0 ). getKeyName(). equals(keyArn. toString())) {
128
- throw new IllegalStateException (" Wrong key ID!" );
129
- }
130
-
131
- // 7. To verify that the encryption context used to decrypt the data was the encryption context you expected,
132
- // examine the encryption context in the result. This helps to ensure that you decrypted the ciphertext that
133
- // you intended.
134
- //
135
- // When verifying, test that your expected encryption context is a subset of the actual encryption context,
136
- // not an exact match. The Encryption SDK adds the signing key to the encryption context when appropriate.
137
- assert decryptResult. getEncryptionContext(). get(" Example" ). equals(" String" );
138
-
139
- // 8. Verify that the decrypted plaintext matches the original plaintext
140
- assert Arrays . equals(decryptResult. getResult(), EXAMPLE_DATA );
141
- }
142
- }
143
- ```
61
+ ### Sample Code
144
62
145
- You can find more examples in the [ examples directory] [ examples ] .
63
+ You can find sample code in the [ examples directory] [ examples ] .
146
64
147
65
## Public API
148
66
0 commit comments