Skip to content

Instantly share code, notes, and snippets.

@abjugard
Created March 11, 2016 15:10
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 abjugard/d6c6b0493a6bdb9a3090 to your computer and use it in GitHub Desktop.
Save abjugard/d6c6b0493a6bdb9a3090 to your computer and use it in GitHub Desktop.
vim wrapper for openssl encryption/decryption
#!/usr/bin/env bash
scriptname=`basename $0`
if [ -z $1 ]
then
echo "$scriptname: File Name Req'd"
echo ""
echo "Usage:"
echo " $scriptname filename.enc"
echo ""
echo "(created/modified files are encrypted using aes-256-cbc)"
exit
fi
file="$1"
tempfile=$(mktemp)
echo -n Password:
read -s pass
echo
openssl="/usr/bin/openssl"
function decrypt {
openssl aes-256-cbc -d -in $file -out $tempfile -pass pass:$pass 2>/dev/null
}
function encrypt {
openssl aes-256-cbc -salt -in $tempfile -out $file -pass pass:$pass 2>/dev/null
}
if [ -f "$file" ]; then
decrypt
if [ $? -ne 0 ]; then
echo "Bad password"
exit
fi
fi
$EDITOR $tempfile
encrypt
rm -f $tempfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment