Skip to content

Instantly share code, notes, and snippets.

@Slakah
Created September 8, 2020 17:08
Show Gist options
  • Save Slakah/65b229895e5285d7ea8076a8536dc4b1 to your computer and use it in GitHub Desktop.
Save Slakah/65b229895e5285d7ea8076a8536dc4b1 to your computer and use it in GitHub Desktop.
Scripts to encrypt and decrypt a file
#!/bin/bash
set -euo pipefail
echoerr() { echo "$@" 1>&2; }
if [[ $# -ne 1 ]]; then
echoerr "Usage: $0 file"
exit 1
fi
readonly ciphertextPath="$(pwd)/$1"
readonly plaintextPath="$(dirname $ciphertextPath)/$(basename $ciphertextPath .enc)"
echo "decrypting $ciphertextPath to $plaintextPath..."
exec aws kms decrypt \
--ciphertext-blob "fileb://$ciphertextPath" --output text --query Plaintext \
| base64 --decode > $plaintextPath
#!/bin/bash
set -euo pipefail
echoerr() { echo "$@" 1>&2; }
if [[ $# -ne 1 ]]; then
echoerr "Usage: $0 file"
exit 1
fi
readonly path="$(pwd)/$1"
readonly keyId='<your kms key here>'
echo "encrypting $path to $path.enc..."
exec aws kms encrypt \
--plaintext "fileb://$path" --output text --query CiphertextBlob \
| base64 --decode > "$path.enc"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment