Created
March 11, 2016 15:10
-
-
Save abjugard/d6c6b0493a6bdb9a3090 to your computer and use it in GitHub Desktop.
vim wrapper for openssl encryption/decryption
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
#!/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