Created
September 8, 2020 17:08
-
-
Save Slakah/65b229895e5285d7ea8076a8536dc4b1 to your computer and use it in GitHub Desktop.
Scripts to encrypt and decrypt a file
This file contains 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
#!/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 |
This file contains 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
#!/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