Encrypt Messages & Files Using OpenSSL on Linux

Share It!

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 Technical World” using Base64 Encoding:

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


  • 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 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:


  • 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:

    Enjoy it!

    Leave a Reply

    Your email address will not be published.