(kms_client)
| 178 | |
| 179 | |
| 180 | def 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 | |
| 211 | if __name__ == "__main__": |
no test coverage detected