@@ -124,18 +124,14 @@ def encrypt_and_decrypt_with_keyring(
124
124
# 6. Decrypt your encrypted data using the same AwsKmsMrkMultiKeyring you used on encrypt.
125
125
# It will decrypt the data using the generator key (in this case, the MRK), since that is
126
126
# the first available KMS key on the keyring that is capable of decrypting the data.
127
- plaintext_bytes , dec_header = client .decrypt (
127
+ plaintext_bytes , _ = client .decrypt (
128
128
source = ciphertext ,
129
- keyring = kms_mrk_multi_keyring
129
+ keyring = kms_mrk_multi_keyring ,
130
+ # Provide the encryption context that was supplied to the encrypt method
131
+ encryption_context = encryption_context ,
130
132
)
131
133
132
- # 7. Demonstrate that the encryption context is correct in the decrypted message header
133
- # (This is an example for demonstration; you do not need to do this in your own code.)
134
- for k , v in encryption_context .items ():
135
- assert v == dec_header .encryption_context [k ], \
136
- "Encryption context does not match expected values"
137
-
138
- # 8. Demonstrate that the decrypted plaintext is identical to the original plaintext.
134
+ # 7. Demonstrate that the decrypted plaintext is identical to the original plaintext.
139
135
# (This is an example for demonstration; you do not need to do this in your own code.)
140
136
assert plaintext_bytes == EXAMPLE_DATA , \
141
137
"Decrypted plaintext should be identical to the original plaintext. Invalid decryption"
@@ -144,7 +140,7 @@ def encrypt_and_decrypt_with_keyring(
144
140
# multi-keyring used to encrypt the data is also capable of decrypting the data.
145
141
# (This is an example for demonstration; you do not need to do this in your own code.)
146
142
147
- # 9 . Create a single AwsKmsMrkKeyring with the replica KMS MRK from the second region.
143
+ # 8 . Create a single AwsKmsMrkKeyring with the replica KMS MRK from the second region.
148
144
149
145
# Create a boto3 client for KMS in the second region which is the region for mrk_replica_key_id.
150
146
second_region_kms_client = boto3 .client ('kms' , region_name = mrk_replica_decrypt_region )
@@ -158,19 +154,15 @@ def encrypt_and_decrypt_with_keyring(
158
154
input = second_region_mrk_keyring_input
159
155
)
160
156
161
- # 10 . Decrypt your encrypted data using the second region AwsKmsMrkKeyring
162
- plaintext_bytes_second_region , dec_header_second_region = client .decrypt (
157
+ # 9 . Decrypt your encrypted data using the second region AwsKmsMrkKeyring
158
+ plaintext_bytes_second_region , _ = client .decrypt (
163
159
source = ciphertext ,
164
- keyring = second_region_mrk_keyring
160
+ keyring = second_region_mrk_keyring ,
161
+ # Provide the encryption context that was supplied to the encrypt method
162
+ encryption_context = encryption_context ,
165
163
)
166
164
167
- # 11. Demonstrate that the encryption context is correct in the decrypted message header
168
- # (This is an example for demonstration; you do not need to do this in your own code.)
169
- for k , v in encryption_context .items ():
170
- assert v == dec_header_second_region .encryption_context [k ], \
171
- "Encryption context does not match expected values"
172
-
173
- # 12. Demonstrate that the decrypted plaintext is identical to the original plaintext.
165
+ # 10. Demonstrate that the decrypted plaintext is identical to the original plaintext.
174
166
# (This is an example for demonstration; you do not need to do this in your own code.)
175
167
assert plaintext_bytes_second_region == EXAMPLE_DATA
176
168
0 commit comments