Last active
July 6, 2017 02:12
-
-
Save nyteshade/adc8a5643f76a8dcf6b50de539f2f5d3 to your computer and use it in GitHub Desktop.
File (de)encryption using openssl
This file contains hidden or 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
# Encryption and decryption BASH functions using openssl | |
function decrypt() { | |
# The first param doesn't contain .enc, write output plus .decrypted if no 2nd | |
if [ "${1/.enc/}" = "${1}" -a -e "${1}" ]; then | |
openssl enc -d -aes-256-cbc -in "${1}" -out "${2:-${1}.decrypted}" | |
# The first param contains .enc, write the output without if no 2nd param | |
elif [ "${1/.enc/}" != "${1}" -a -e "${1}" ]; then | |
openssl enc -d -aes-256-cbc -in "${1}" -out "${2:-${1/.enc/}}" | |
# Just accept first and second an fail if necessary | |
else | |
openssl enc -d -aes-256-cbc -in "${1}" -out "${2}" | |
fi | |
} | |
function encrypt() { | |
# The first param doesn't contain .enc, write output plus .enc if no 2nd | |
if [ "${1/.enc/}" = "${1}" -a -e "${1}" ]; then | |
openssl enc -salt -aes-256-cbc -in "${1}" -out "${2:-${1}.enc}" | |
# Just accept first and second an fail if necessary | |
else | |
openssl enc -salt -aes-256-cbc -in "${1}" -out "${2}" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use,
cat functions.sh >> .bashrc