Although there are many tutorials concerning encrypting files sometimes one wants just to encrypt/decrypt files with only a passphrase. This what this article is about.
This article is based on the great tutorials found at: http://bitflop.com/document/86.
For a fuller Tutorial on GnuPG: http://bitflop.com/document/129
Thanks to the author for the good work.

GnuPG

Encryption:
$ gpg -c --cipher-algo AES256 $filename
Results is a file called filename.gpg

Or maybe a bit more complex:
gpg -v -c --yes --cipher-algo AES256 --passphrase $ENCRPW -o "$ENCRDIR/$file" "$file"
This above command will:
– Encrypt the file using the password stored in variable $ENCRPW
– Put the new encrypted file into another directory($ENCRDIR/) under the same filename as the original (no .gpg)
– Overwrite the existing GPG file without asking (- -yes)

Decryption:
$ gpg filename.gpg

Decryption from PHP script
Using a Linux system call.
gpg --batch --passphrase $ENCRPW --no-tty -o $tempdir -d $pgpfile
$tempdir is a path for a temporary file that will be generated randomly
and deleted when the file has been downloaded to the browser.
$gpgfile: PGP filename to decrypt and send to Browser incl. path.

Mcrypt

In this example I am also using compression.
Encryption with compression:
$ mcrypt -z -a rijndael-256 filename
Decryption with compression:
$ mcrypt -z -d filename
See man mcrypt for more information and mcrypt –list for at list of the different supported algorithms.

OpenSSL

Encryption:
$ openssl aes-256-cbc -e -in filename -out encrypted_filename
Decryption:
$ openssl aes-256-cbc -d -in encrypted_filename -out filename