44
44
def encrypt_and_decrypt_with_keyring (
45
45
mrk_key_id_encrypt : str ,
46
46
mrk_replica_key_id_decrypt : str ,
47
- default_region : str ,
48
- second_region : str
47
+ mrk_encrypt_region : str ,
48
+ mrk_replica_decrypt_region : str
49
49
):
50
50
"""Demonstrate an encrypt/decrypt cycle using an AWS KMS MRK keyring.
51
51
52
52
Usage: encrypt_and_decrypt_with_keyring(mrk_key_id_encrypt,
53
53
mrk_replica_key_id_decrypt,
54
- default_region ,
55
- second_region )
54
+ mrk_encrypt_region ,
55
+ mrk_replica_decrypt_region )
56
56
:param mrk_key_id_encrypt: KMS Key identifier for the KMS key located in your
57
57
default region, which you want to use for encryption of your data keys
58
58
:type mrk_key_id_encrypt: string
59
- :param mrk_replica_key_id_decrypt: KMS Key identifier for the KMS key KMS Key
59
+ :param mrk_replica_key_id_decrypt: KMS Key identifier for the KMS key
60
60
that is a replica of the `mrk_key_id_encrypt` in a second region, which you
61
61
want to use for decryption of your data keys
62
62
:type mrk_replica_key_id_decrypt: string
63
- :param default_region: AWS Region for encryption of your data keys
64
- :type default_region: string
65
- :param second_region: AWS Region for decryption of your data keys
66
- :type second_region: string
67
-
68
- For more information on KMS Key identifiers, see
63
+ :param mrk_encrypt_region: AWS Region for encryption of your data keys. This should
64
+ be the region of the mrk_key_id_encrypt.
65
+ :type mrk_encrypt_region: string
66
+ :param mrk_replica_decrypt_region: AWS Region for decryption of your data keys. This should
67
+ be the region of the mrk_replica_key_id_decrypt.
68
+ :type mrk_replica_decrypt_region: string
69
+
70
+ For more information on KMS Key identifiers for multi-region keys, see
69
71
https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id
70
72
"""
71
73
# 1. Instantiate the encryption SDK client.
@@ -91,13 +93,13 @@ def encrypt_and_decrypt_with_keyring(
91
93
"the data you are handling" : "is what you think it is" ,
92
94
}
93
95
94
- # 3. Create a keyring that will encrypt your data, using a KMS MRK key in the first region.
96
+ # 3. Create a keyring that will encrypt your data, using a KMS MRK in the first region.
95
97
mat_prov : AwsCryptographicMaterialProviders = AwsCryptographicMaterialProviders (
96
98
config = MaterialProvidersConfig ()
97
99
)
98
100
99
101
# Create a boto3 client for KMS in the first region.
100
- encrypt_kms_client = boto3 .client ('kms' , region_name = default_region )
102
+ encrypt_kms_client = boto3 .client ('kms' , region_name = mrk_encrypt_region )
101
103
102
104
encrypt_keyring_input : CreateAwsKmsMrkKeyringInput = CreateAwsKmsMrkKeyringInput (
103
105
kms_key_id = mrk_key_id_encrypt ,
@@ -120,11 +122,11 @@ def encrypt_and_decrypt_with_keyring(
120
122
assert ciphertext != EXAMPLE_DATA , \
121
123
"Ciphertext and plaintext data are the same. Invalid encryption"
122
124
123
- # 6. Create a keyring that will decrypt your data, using the same KMS MRK key replicated
125
+ # 6. Create a keyring that will decrypt your data, using the same KMS MRK replicated
124
126
# to the second region. This example assumes you have already replicated your key
125
127
126
128
# Create a boto3 client for KMS in the second region.
127
- decrypt_kms_client = boto3 .client ('kms' , region_name = second_region )
129
+ decrypt_kms_client = boto3 .client ('kms' , region_name = mrk_replica_decrypt_region )
128
130
129
131
decrypt_keyring_input : CreateAwsKmsMrkKeyringInput = CreateAwsKmsMrkKeyringInput (
130
132
kms_key_id = mrk_replica_key_id_decrypt ,
0 commit comments