1
1
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2
2
# SPDX-License-Identifier: Apache-2.0
3
3
"""
4
- This example sets up the AWS Cryptographic Material Managers (CMM).
4
+ This example sets up the default Cryptographic Material Managers (CMM).
5
5
6
- The AWS cryptographic materials manager (CMM) assembles the cryptographic materials
6
+ The default cryptographic materials manager (CMM) assembles the cryptographic materials
7
7
that are used to encrypt and decrypt data. The cryptographic materials include
8
8
plaintext and encrypted data keys, and an optional message signing key.
9
9
This example creates a CMM and then encrypts a custom input EXAMPLE_DATA
15
15
3. Decrypted plaintext value matches EXAMPLE_DATA
16
16
These sanity checks are for demonstration in the example only. You do not need these in your code.
17
17
18
- For more information on AWS Cryptographic Material Managers, see
18
+ For more information on Cryptographic Material Managers, see
19
19
https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#crypt-materials-manager
20
20
"""
21
21
import sys
41
41
EXAMPLE_DATA : bytes = b"Hello World"
42
42
43
43
44
- def encrypt_and_decrypt_with_cmm (
44
+ def encrypt_and_decrypt_with_default_cmm (
45
45
kms_key_id : str
46
46
):
47
- """Demonstrate an encrypt/decrypt cycle using an AWS Cryptographic Material Managers.
47
+ """Demonstrate an encrypt/decrypt cycle using default Cryptographic Material Managers.
48
48
49
- Usage: encrypt_and_decrypt_with_cmm (kms_key_id)
49
+ Usage: encrypt_and_decrypt_with_default_cmm (kms_key_id)
50
50
:param kms_key_id: KMS Key identifier for the KMS key you want to use for encryption and
51
51
decryption of your data keys.
52
52
:type kms_key_id: string
@@ -77,7 +77,7 @@ def encrypt_and_decrypt_with_cmm(
77
77
"the data you are handling" : "is what you think it is" ,
78
78
}
79
79
80
- # 4 . Create a KMS keyring to use with the CryptographicMaterialsManager
80
+ # 3 . Create a KMS keyring to use with the CryptographicMaterialsManager
81
81
kms_client = boto3 .client ('kms' , region_name = "us-west-2" )
82
82
83
83
mat_prov : AwsCryptographicMaterialProviders = AwsCryptographicMaterialProviders (
@@ -93,7 +93,7 @@ def encrypt_and_decrypt_with_cmm(
93
93
input = keyring_input
94
94
)
95
95
96
- # 5 . Create a CryptographicMaterialsManager for encryption and decryption
96
+ # 4 . Create a CryptographicMaterialsManager for encryption and decryption
97
97
cmm_input : CreateDefaultCryptographicMaterialsManagerInput = \
98
98
CreateDefaultCryptographicMaterialsManagerInput (
99
99
keyring = kms_keyring
@@ -103,31 +103,31 @@ def encrypt_and_decrypt_with_cmm(
103
103
input = cmm_input
104
104
)
105
105
106
- # 6 . Encrypt the data with the encryptionContext.
106
+ # 5 . Encrypt the data with the encryptionContext.
107
107
ciphertext , _ = client .encrypt (
108
108
source = EXAMPLE_DATA ,
109
109
materials_manager = cmm ,
110
110
encryption_context = encryption_context
111
111
)
112
112
113
- # 7 . Demonstrate that the ciphertext and plaintext are different.
113
+ # 6 . Demonstrate that the ciphertext and plaintext are different.
114
114
# (This is an example for demonstration; you do not need to do this in your own code.)
115
115
assert ciphertext != EXAMPLE_DATA , \
116
116
"Ciphertext and plaintext data are the same. Invalid encryption"
117
117
118
- # 8 . Decrypt your encrypted data using the same cmm you used on encrypt.
118
+ # 7 . Decrypt your encrypted data using the same cmm you used on encrypt.
119
119
plaintext_bytes , dec_header = client .decrypt (
120
120
source = ciphertext ,
121
121
materials_manager = cmm
122
122
)
123
123
124
- # 9 . Demonstrate that the encryption context is correct in the decrypted message header
124
+ # 8 . Demonstrate that the encryption context is correct in the decrypted message header
125
125
# (This is an example for demonstration; you do not need to do this in your own code.)
126
126
for k , v in encryption_context .items ():
127
127
assert v == dec_header .encryption_context [k ], \
128
128
"Encryption context does not match expected values"
129
129
130
- # 10 . Demonstrate that the decrypted plaintext is identical to the original plaintext.
130
+ # 9 . Demonstrate that the decrypted plaintext is identical to the original plaintext.
131
131
# (This is an example for demonstration; you do not need to do this in your own code.)
132
132
assert plaintext_bytes == EXAMPLE_DATA , \
133
133
"Decrypted plaintext should be identical to the original plaintext. Invalid decryption"
0 commit comments