Encrypting and decrypting files using GnuPG, OpenSSL or Mcrypt

Posted on 01.04.2009 by Kim N. Lesmer. Last updated on 26.07.2016.
How to encrypt and decrypt a file with GnuPG, OpenSSL LibreSSL or Mcrypt using the Advanced Encryption Standard and a passphrase.



$ gpg -c --cipher-algo AES256 filename

Results in a file called filename.gpg


$ gpg filename.gpg


In this example I am also using compression.

Encryption with compression:

$ mcrypt -z -a rijndael-256 filename

Decryptation with compression:

$ mcrypt -z -d filename

Se man mcrypt for more information and mcrypt --list for at list of the different supported alghorithems.

OpenSSL LibreSSL

Use LibreSSL instead of OpenSSL. It's still the same command, but LibreSSL is a version of the TLS/crypto stack forked from OpenSSL in 2014 by OpenBSD, with goals of modernizing the codebase, improving security, and applying best practice development processes.


$ openssl aes-256-cbc -e -in filename -out encrypted_filename


$ openssl aes-256-cbc -d -in encrypted_filename -out filename

If you have any comments or corrections feel free to email them to me.