ENCRYPTION AND DECRYPTION WITH GNUPG


So now it is time to get to the good part, Woohoo !! We get to ACTUALLY use GnuPG/GPG. Here we will use it to encrypt & decrypt stuff.


Oh & Please note that you cannot encrypt folders, ONLY FILES & MESSAGES can be encrypted, of course you can just convert/pack up the folders into compressed files called TarBalls [One of my scripts from the SimpleScripts-Repository can do that]. In order to encrypt a file just type:
 gpg -r EMAIL_ID -e FILE_NAME 
		OR 
 gpg --encrypt --recipient EMAIL_ID FILE_NAME

				ALTERNATIVELY YOU CAN USE THIS
				
 gpg -r EMAIL_ID -o NEW_FILE_NAME -e FILE_NAME 
		OR 
 gpg --encrypt --output NEW_FILE_NAME --recipient EMAIL_ID FILE_NAME

The encrypted-file will have an extension ".gpg" given automatically by GnuPG/GPG by DEFAULT or it will have the ".asc" extension instead if you use the "armor" option in the command.


Now in order to DECRYPT the encrypted file and maybe redirect the ouput to a file of a name of your choosing [Here; "--output" & "-o" are the same], just type:

 gpg -d FILE_NAME.gpg > FILE_NAME
		OR
 gpg --decrypt --output NEW_FILE_NAME FILE_NAME.gpg
		OR
 gpg --decrypt -o NEW_FILE_NAME FILE_NAME.gpg

Now if you wanted to encrypt a text-message ONLY & not an entire file containing a text-message then simply do the following & copy the results into a file:

echo "YOUR_MESSAGE" | gpg -e --armor -r EMAIL_ID
        OR 
echo "YOUR_MESSAGE" | gpg --encrypt --armor -r EMAIL_ID

REMINDER; here the file will not have a .gpg extension as the file was created by you seperately, ONLY the message was encrypted [AKA the text]. So now in order to decrypt it, you can simply do the following:

cat MESSAGE_FILE | gpg -d
		OR
cat MESSAGE_FILE | gpg --decrypt

In both cases you are "piping" [Denoted by the symbol* "|"] the message & the file containing the message into GnuPG/GPG.

Oh & I almost forgot
if you want to encrypt your files for yourself then just "set the recipient to YOUR EMAIL-ID".