Skip to content

Instantly share code, notes, and snippets.

@wesleyit
Created November 19, 2019 17:00
Show Gist options
  • Save wesleyit/d3e401e7ecdb0d669e64bac72256e15e to your computer and use it in GitHub Desktop.
Save wesleyit/d3e401e7ecdb0d669e64bac72256e15e to your computer and use it in GitHub Desktop.
Helper to encrypt and decrypt using AWS KMS
#!/bin/bash
export PROFILE='my-security-profile'
export KEY='12345678-abcd-efgh-ijkl-1234567890'
function encrypt() {
aws --profile "$PROFILE" \
kms encrypt \
--key-id "$KEY" \
--plaintext "file://$1" \
--output text \
--query CiphertextBlob |\
base64 --decode > "encrypted_$1"
}
function decrypt() {
aws --profile "$PROFILE" \
kms decrypt \
--ciphertext-blob "fileb://$1" \
--output text \
--query Plaintext |\
base64 --decode > "${1/encrypted_/decrypted_}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment