3
3
"""
4
4
This example sets up the AWS KMS RSA Keyring
5
5
6
- The AWS KMS RSA keyring uses asymmetric encryption KMS RSA keys to generate, encrypt and
7
- decrypt data keys. This example creates a KMS RSA Keyring and then encrypts a custom input
6
+ This example creates a KMS RSA Keyring and then encrypts a custom input
8
7
EXAMPLE_DATA with an encryption context. This example also includes some sanity checks for
9
8
demonstration:
10
9
1. Ciphertext and plaintext data are not the same
11
10
2. Encryption context is correct in the decrypted message header
12
11
3. Decrypted plaintext value matches EXAMPLE_DATA
13
12
These sanity checks are for demonstration in the example only. You do not need these in your code.
14
- """
15
- #
16
- # AWS KMS RSA keyrings can be used independently or in a multi-keyring with other keyrings
17
- # of the same or a different type.
18
13
19
14
# For more information on how to use KMS keyrings, see
20
15
# https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/use-kms-keyring.html
16
+ """
21
17
import sys
22
18
23
19
import boto3
29
25
30
26
import aws_encryption_sdk
31
27
from aws_encryption_sdk import CommitmentPolicy
28
+ from aws_encryption_sdk .identifiers import AlgorithmSuite
32
29
33
30
# TODO-MPL: Remove this as part of removing PYTHONPATH hacks.
34
31
MODULE_ROOT_DIR = '/' .join (__file__ .split ("/" )[:- 1 ])
39
36
40
37
41
38
def encrypt_and_decrypt_with_keyring (
42
- kms_rsa_key_id : str
39
+ kms_rsa_key_id : str ,
40
+ kms_rsa_public_key : str
43
41
):
44
42
"""Demonstrate an encrypt/decrypt cycle using an AWS KMS RSA keyring.
45
43
46
- Usage: encrypt_and_decrypt_with_keyring(kms_rsa_key_id)
47
- :param kms_rsa_key_id: KMS RSA Key identifier for the KMS RSA key you want to use for
48
- encryption and decryption of your data keys.
44
+ Usage: encrypt_and_decrypt_with_keyring(kms_rsa_key_id, kms_rsa_public_key)
45
+ :param kms_rsa_key_id: KMS RSA Key identifier for the KMS RSA key you want to use
49
46
:type kms_rsa_key_id: string
47
+ :param kms_rsa_public_key: KMS RSA public key you want to use
48
+ :type kms_rsa_public_key: string
50
49
51
50
For more information on KMS Key identifiers, see
52
51
https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id
@@ -78,17 +77,6 @@ def encrypt_and_decrypt_with_keyring(
78
77
}
79
78
80
79
# 4. Create a KMS RSA keyring
81
- kms_rsa_public_key = '''-----BEGIN PUBLIC KEY-----
82
- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA27Uc/fBaMVhxCE/SpCMQ
83
- oSBRSzQJw+o2hBaA+FiPGtiJ/aPy7sn18aCkelaSj4kwoC79b/arNHlkjc7OJFsN
84
- /GoFKgNvaiY4lOeJqEiWQGSSgHtsJLdbO2u4OOSxh8qIRAMKbMgQDVX4FR/PLKeK
85
- fc2aCDvcNSpAM++8NlNmv7+xQBJydr5ce91eISbHkFRkK3/bAM+1iddupoRw4Wo2
86
- r3avzrg5xBHmzR7u1FTab22Op3Hgb2dBLZH43wNKAceVwKqKA8UNAxashFON7xK9
87
- yy4kfOL0Z/nhxRKe4jRZ/5v508qIzgzCksYy7Y3QbMejAtiYnr7s5/d5KWw0swou
88
- twIDAQAB
89
- -----END PUBLIC KEY-----
90
- '''
91
-
92
80
mat_prov : AwsCryptographicMaterialProviders = AwsCryptographicMaterialProviders (
93
81
config = MaterialProvidersConfig ()
94
82
)
@@ -108,7 +96,8 @@ def encrypt_and_decrypt_with_keyring(
108
96
ciphertext , _ = client .encrypt (
109
97
source = EXAMPLE_DATA ,
110
98
keyring = kms_rsa_keyring ,
111
- encryption_context = encryption_context
99
+ encryption_context = encryption_context ,
100
+ algorithm = AlgorithmSuite .AES_256_GCM_HKDF_SHA512_COMMIT_KEY
112
101
)
113
102
114
103
# 6. Demonstrate that the ciphertext and plaintext are different.
0 commit comments