How to Encrypt Messages & Files Using OpenSSL on Linux

OpenSSL is an effective cryptography toolbox. Many of us have used OpenSSL for making RSA Private Keys or CSR (Certificate Signing Request). However, did you realize that you can use OpenSSL to encrypt files or messages? This article will assist you how to encrypt messages and files using OpenSSL.

Encrypt and Decrypt Messages

The following command will encrypt message “Welcome to 567ss.com” using Base64 Encoding:

# echo “Welcome to 567ss.com” | openssl enc -base64

D2VsY29tZSB0byA1Njdzcy5jb20K

Note:

 enc: Encoding with Ciphers

 -base64: Base64 Encoding

To decrypt the message we need to reverse the order and use -d option for decryption.

# echo “D2VsY29tZSB0byA1Njdzcy5jb20K” | openssl enc -base64 -d

Welcome to 567ss.com

Encrypt and Decrypt File:

To encrypt the file use the following command:

# openssl enc -aes-256-cbc -in /etc/fstab -out fstab.dat

enter aes-256-cbc encryption password:

Verifying – enter aes-256-cbc encryption password:

Note:

 enc: Encoding with Ciphers

 -aes-256-cbc: The Encryption Cipher

 -out: enc option used to specify the name of the out filename

To decrypt the file use following command:

# openssl enc -aes-256-cbc -d -in fstab.dat > fstab.txt

enter aes-256-cbc decryption password: