Using OpenSSL to Encrypt-Decrypt data

Configurare noua (How To)

Situatie

OpenSSL can function as a standalone tool for encryption. Among the various encryption algorithms it supports, we will use AES to encrypt a text file directly from the command line using KaliLinux.

Solutie

Pasi de urmat

Step a) Encrypting a message in OPENSSL

1)-Type the command below to list the contents of the encrypted secret_message.txt text file on the screen:

cat secret_message

2) -In the same terminal window, run the following command to encrypt the text file using AES-256. The encrypted file will be saved as message.enc. OpenSSL will prompt you to enter and confirm a password. Ensure you provide the password as requested and remember it for future use.

openssl aes-256-cbc -in secret_message -out message.enc

-Once the process is complete, use the cat command to view the contents of the message.enc file.

cat message.enc

3)-To make the file readable, rerun the OpenSSL command, this time including the -a option. The -a option instructs OpenSSL to encode the encrypted message in Base64 format before saving it to a file.

openssl aes-256-cbc -a -in Secret_message -out message.enc

-Again, use the cat command to view the contents of the newly generated message.enc file

cat message.enc

Step b) Decrypting a message in OPENSSL

A similar OpenSSL command can be used to decrypt the message.enc file.

-Run the following command to decrypt message.enc:

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

OpenSSL will prompt you to enter the password used during encryption. Provide the same password.
Once the decryption is complete, OpenSSL will save the decrypted message in a text file named decrypted_Secret_message.txt

-Use cat to display the contents of decrypted_letter.txt.

Tip solutie

Permanent

Voteaza

(6 din 11 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?