Image

Knowledge base → Encrypting files using OpenSSL in the Linux console

[Virtual servers]
Date of publication: 10.10.2023

To encrypt files in the Linux console, we will use the OpenSSL package. This package has a large number of settings; we will list the main ones for file encryption.

1. File encryption

openssl enc -aes-256-cbc -salt -in file1.txt -out file1.txt.enc

  enc - Coding using ciphers
-aes-256-cbc - Cipher algorithm to use
-salt - Adds encryption strength
-in - Specifies the input file
-out - Specifies the output file

2. File decryption

openssl enc -aes-256-cbc -d -in file1.txt.enc -out file1.txt

-d - Decrypts data
-in - Specifies data to decrypt
-out - Specifies a file to place the decrypted data in

3. Encryption methods

3.1 In order to send an encrypted piece of text by mail or chat without losing the integrity of the cipher(data), you must encrypt it in Base64 format.

Base64 encoding is a standard method of converting 8-bit binary information into a limited subset of ASCII characters. It is necessary for secure transport through email systems, instant messengers, which are not 8-bit, since by default the encrypted file is in binary format.

openssl enc -aes-256-cbc -salt -a -in file1.txt -out file1.txt.enc

-a - makes encrypted data Base64 encoded.

Base64 Decoding

openssl enc -aes-256-cbc -d -a -in file1.txt.enc -out file1.txt




No Comments Yet