Created
April 6, 2023 17:14
-
-
Save nicksnell/cd73bf67a666002dc5f787fef0c6ecbc to your computer and use it in GitHub Desktop.
Decode a KMS value using a specific key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import boto3 | |
import os | |
encoded = os.environ.get("ENCODED") | |
key_arn = os.environ.get("KEY") | |
profile = os.environ.get("PROFILE") | |
if key_arn is None or encoded is None: | |
raise Exception("You must provide a key & encoded values!") | |
session = boto3.session.Session(profile_name=profile) | |
kms = session.client("kms") | |
meta = kms.decrypt( | |
KeyId=key_arn, | |
CiphertextBlob=base64.b64decode(encoded) | |
) | |
plaintext = meta["Plaintext"] | |
print(plaintext.decode()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment