Skip to content

Instantly share code, notes, and snippets.

@geraldstanje
Created March 9, 2018 02:41
Show Gist options
  • Save geraldstanje/83501d0c5cc730715e58dea5568f1a8f to your computer and use it in GitHub Desktop.
Save geraldstanje/83501d0c5cc730715e58dea5568f1a8f to your computer and use it in GitHub Desktop.
kms encrypt decrypt
#!/usr/bin/env bash
if [ -z ${KMS_KEY_ID} ]; then
echo "KMS_KEY_ID unset! Exiting";
exit 1
fi
aws kms encrypt --key-id $KMS_KEY_ID --plaintext "hello" --output text --query CiphertextBlob > output.kms.yml
encrypted=$(<output.kms.yml)
echo "Encrypted: $encrypted"
echo "Decrypted: $(aws kms decrypt --ciphertext-blob fileb://<(echo $encrypted | base64 -D) --query Plaintext --output text | base64 -D)"
@geraldstanje
Copy link
Author

blob=AQECAHiBTXMxAMpI9Q4CfAD79nib3Vbut33Rr3ikKtQRWAQQFgAAAHYwdAYJKoZIhvcNAQcGoGcwZQIBADBgBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDFLZAunRHyfzsY41VwIBEIAzHu7FfSLsFIPshfhTmGq3yrSlv/BDfofTyFbL/wXuwy+sM9nYjWZmJbFNCBWadebHH9eh
aws kms decrypt --ciphertext-blob fileb://<(echo $blob | base64 -D) --query Plaintext --output text

@geraldstanje
Copy link
Author

$ aws kms decrypt --ciphertext-blob fileb://<(echo $blob | base64 -D) --query Plaintext --output text | md5sum
58772456fdb775906dcdb1adbe9100e5 -

@geraldstanje
Copy link
Author

make sure aws uses us-east-1 region

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment