Encrypting and decrypting files using GnuPG, OpenSSL or Mcrypt
Published on 2009-04-01. Modified on 2016-07-26.
How to encrypt and decrypt a file with GnuPG, OpenSSL or LibreSSL, or Mcrypt using the Advanced Encryption Standard and a password phrase.
$ gpg -c --cipher-algo AES256 filename
Results in a file called
$ gpg filename.gpg
In this example I am also using compression.
Encryption with compression:
$ mcrypt -z -a rijndael-256 filename
Decryption with compression:
$ mcrypt -z -d filename
Se man mcrypt for more information and
mcrypt --list for at list of the different supported algorithms.
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