Skip to content

Instantly share code, notes, and snippets.

@pramsey
Created July 21, 2016 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pramsey/ae62f58a59c5acdfdbc7e6acbb019d95 to your computer and use it in GitHub Desktop.
Save pramsey/ae62f58a59c5acdfdbc7e6acbb019d95 to your computer and use it in GitHub Desktop.
bash short-cuts for file encryption
#
# 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