Using bash for quick encryption/decryption.
I was playing around tonight, and I started messing around with gpg again.... and came up with some functions to encrypt from the shell.
Usually from the shell, i've cd'd into the directory and have done an ls so see what was in there..... so if i wanted to encrypt a file in the directory called "crouse.txt" I would now simply type
encrypt crouse.txt
to decrypt
decrypt crouse.txt
and if it's an image/audio or other binary file
to encrypt
bencrypt someimage.jpg
decryption is the same
decrypt someimage.jpg
You CAN encrypt the binary files with the ascii armor (the first way using "encrypt", this was just another option)
Simply place the following functions into your
.bashrc file in your home directory. The function
pe is the pass phrase encryption program i wrote before and modified to run as a function. The
keys function opens up the Kgpg keymanager.
Code:
################### Begin gpg functions ##################
encrypt ()
{
# Use ascii armor
gpg -ac --no-options "$1"
}
bencrypt ()
{
# No ascii armor
# Encrypt binary data. jpegs/gifs/vobs/etc.
gpg -c --no-options "$1"
}
decrypt ()
{
gpg --no-options "$1"
}
pe ()
{
# Passphrase encryption program
# Created by Dave Crouse 01-13-2006
# Reads input from text editor and encrypts to screen.
clear
echo " Passphrase Encryption Program";
echo "--------------------------------------------------"; echo "";
which $EDITOR &>/dev/null
if [ $? != "0" ];
then
echo "It appears that you do not have a text editor set in your .bashrc file.";
echo "What editor would you like to use ? " ;
read EDITOR ; echo "";
fi
echo "Enter the name/comment for this message :"
read comment
$EDITOR passphraseencryption
gpg --armor --comment "$comment" --no-options --output passphraseencryption.gpg --symmetric passphraseencryption
shred -u passphraseencryption ; clear
echo "Outputting passphrase encrypted message"; echo "" ; echo "" ;
cat passphraseencryption.gpg ; echo "" ; echo "" ;
shred -u passphraseencryption.gpg ;
read -p "Hit enter to exit" temp; clear
}
keys ()
{
# Opens up kgpg keymanager
kgpg -k
}
################### End gpg functions ##################