Created
May 26, 2014 06:26
-
-
Save kevin-ashton/0ceae55fc2541e2abe83 to your computer and use it in GitHub Desktop.
Encrypt a file using gpg with shell wrappers (parameters into shell)
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
#!/bin/bash | |
#First we make sure they have input a parameter for the program to encrypt | |
if [ "$1" = "" ]; then | |
echo Must have a file to encrypt | |
exit | |
fi | |
echo Please, enter your password | |
#stty turns on and off a type of output. We don't want the password to be in clear text so we disable it with "stty -echo". Aftwards we return the output to it's orginal state with "stty $stty_orig". | |
stty_orig=`stty -g` | |
stty -echo | |
read P1 | |
stty $stty_orig | |
echo Please, enter password again | |
stty_orig=`stty -g` | |
stty -echo | |
read P2 | |
stty $stty_orig | |
#We double to check to make sure they entered the same password both times. Only then do we encrypt the file. | |
if [ "$P1" = "$P2" ]; then | |
gpg -c --passphrase $P1 $1 | |
rm $1 | |
echo File Encrypted | |
else | |
echo Passwords did not match | |
fi |
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
#!/bin/bash | |
#first check to make sure they have input a file name to decrypt | |
if [ "$1" = "" ]; then | |
echo Must have a file to decrypt | |
exit | |
fi | |
echo Please, enter your password | |
#stty turns on and off a type of output. We don't want the password to be in clear text so we disable it with "stty -echo". Aftwards we return the output to it's orginal state with "stty $stty_orig". | |
stty_orig=`stty -g` | |
stty -echo | |
read P1 | |
stty $stty_orig | |
gpg --passphrase $P1 $1 &> /dev/null | |
# The "$?" use a special variable that returns a number based on if an operation was successful or not. When it returns a 0 then the operation was succesful hence only then do we want to delete the encrypted file. | |
if [ $? == 0 ]; then | |
echo File Decrypted | |
rm $1 | |
else | |
echo Incorrect Password | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment