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 in how to encrypt messages and files using OpenSSL.
Encrypt

Encrypt and Decrypt Messages

The following command will encrypt the message “Welcome to Technical World” using Base64 Encoding:

# echo "Welcome to Technical World" | openssl enc -base64
V2VsY29tZSB0byBUZWNobmljYWwgV29ybGQK

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 "V2VsY29tZSB0byBUZWNobmljYWwgV29ybGQK" | openssl enc -base64 -d
Welcome to Technical World

Encrypt and Decrypt File:

To encrypt the file using 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:

 

Read More: rsync man page

Enjoy it!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.