Decrypts text previously encrypted with a key. :param key_id: The ARN or ID of the key used to decrypt the data. :param cipher_text: The encrypted text to decrypt. :return: The decrypted text.
(self, key_id: str, cipher_text: bytes)
| 65 | |
| 66 | # snippet-start:[python.example_code.kms.Decrypt] |
| 67 | def decrypt(self, key_id: str, cipher_text: bytes) -> str: |
| 68 | """ |
| 69 | Decrypts text previously encrypted with a key. |
| 70 | |
| 71 | :param key_id: The ARN or ID of the key used to decrypt the data. |
| 72 | :param cipher_text: The encrypted text to decrypt. |
| 73 | :return: The decrypted text. |
| 74 | """ |
| 75 | try: |
| 76 | return self.kms_client.decrypt(KeyId=key_id, CiphertextBlob=cipher_text)[ |
| 77 | "Plaintext" |
| 78 | ].decode() |
| 79 | except ClientError as err: |
| 80 | logger.error( |
| 81 | "Couldn't decrypt your ciphertext. Here's why: %s", |
| 82 | err.response["Error"]["Message"], |
| 83 | ) |
| 84 | raise |
| 85 | |
| 86 | # snippet-end:[python.example_code.kms.Decrypt] |
| 87 |
no outgoing calls
no test coverage detected