Created
July 21, 2016 04:16
-
-
Save pramsey/ae62f58a59c5acdfdbc7e6acbb019d95 to your computer and use it in GitHub Desktop.
bash short-cuts for file encryption
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
# | |
# Simple commandline encryption aliases for OSX. | |
# Put this in your .bash_profile | |
# | |
# encrypt myfile | |
# takes your password, encrypts myfile to myfile.enc, | |
# writes some random data into myfile and then deletes it | |
# | |
# decrypt myfile.enc | |
# takes your passowrd, decrypts to myfile, | |
# and removes myfile.enc | |
# | |
do_encrypt() { | |
if [ -f $1 ]; then | |
openssl aes-256-cbc -salt -in $1 -out $1.enc | |
sz=`stat -f%z $1` | |
if [ $? -eq 0 ]; then | |
head -c $sz < /dev/random > $1 | |
/bin/rm $1 | |
fi | |
fi | |
} | |
do_decrypt() { | |
if [ -f $1 ]; then | |
bn=`basename $1 .enc` | |
if [ $bn == $1 ]; then | |
bn=$1.plain | |
fi | |
openssl aes-256-cbc -d -in $1 -out $bn | |
if [ $? -eq 0 ]; then | |
/bin/rm $1 | |
fi | |
fi | |
} | |
alias encrypt=do_encrypt | |
alias decrypt=do_decrypt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment