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

Method decrypt

python/example_code/kms/key_encryption.py:67–84  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 5

key_encryptionFunction · 0.95
kms_scenarioMethod · 0.80
decryptDataAsyncMethod · 0.80
decryptDataMethod · 0.80
mainMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected