Skip to content

Instantly share code, notes, and snippets.

@gilbertfrancois
Last active March 1, 2022 15:15
Show Gist options
  • Save gilbertfrancois/f608c5cc70686e4fbee5224694c34cc9 to your computer and use it in GitHub Desktop.
Save gilbertfrancois/f608c5cc70686e4fbee5224694c34cc9 to your computer and use it in GitHub Desktop.
Shell functions to easily encrypt and decrypt files using AES256-CBC with openssl.
# Add `source enc.sh` to your .bashrc, .profile or .zshrc to include these functions.
#
# For encryption, type:
# $ enc myfile
#
# For decryption, type:
# $ dec myfile.enc
function enc() {
if [ $# -eq 0 ]; then
echo "example: "
echo " enc myfile.tar.gz"
else
openssl enc -aes-256-cbc -pbkdf2 -e -in ${1} -out ${1}.enc
fi
}
function dec() {
if [ $# -eq 0 ]; then
echo "example: "
echo " dec myfile.tar.gz.enc"
else
filename=${1}
filename_noext=${filename%.*}
extension=${filename##*.}
openssl enc -aes-256-cbc -pbkdf2 -d -in ${filename} -out ${filename_noext}
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment