MCPcopy Create free account
hub / github.com/awsdocs/aws-doc-sdk-examples / key_encryption

Function key_encryption

python/example_code/kms/key_encryption.py:180–208  ·  view source on GitHub ↗
(kms_client)

Source from the content-addressed store, hash-verified

178
179
180def key_encryption(kms_client):
181 logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
182
183 print("-" * 88)
184 print("Welcome to the AWS Key Management Service (AWS KMS) key encryption demo.")
185 print("-" * 88)
186
187 key_id = input("Enter a key ID or ARN to start the demo: ")
188 if key_id == "":
189 print("A key is required to run this demo.")
190 return
191
192 key_encrypt = KeyEncrypt(kms_client)
193 text = input("Enter some text to encrypt: ")
194 cipher_text = key_encrypt.encrypt(key_id, text)
195 print(f"Your ciphertext is: {cipher_text}")
196 print("-" * 88)
197 if cipher_text is not None:
198 answer = input("Ready to decrypt your ciphertext (y/n)? ")
199 if answer.lower() == "y":
200 decrypted_text = key_encrypt.decrypt(key_id, cipher_text)
201 print(f"Your plaintext is {decrypted_text}")
202 print("-" * 88)
203 key_encrypt.re_encrypt(key_id, cipher_text)
204 else:
205 print("Skipping decryption demo.")
206
207 print("\nThanks for watching!")
208 print("-" * 88)
209
210
211if __name__ == "__main__":

Callers 1

key_encryption.pyFile · 0.85

Calls 4

encryptMethod · 0.95
decryptMethod · 0.95
re_encryptMethod · 0.95
KeyEncryptClass · 0.85

Tested by

no test coverage detected