In this section, we are going to learn about OpenSSL. In this section, we are going encrypt and decrypt messages and files using OpenSSL.
Besides having a terminal open, you need to have a basic knowledge of encoding and decoding schemes.
- We are going to encrypt and decrypt simple messages. We will use the -base64 encoding scheme. First, we will encrypt a message. Run the following command in the terminal:
$ echo "Welcome to Bash Cookbook" | openssl enc -base64
- To decrypt the message, run following command in the terminal:
$ echo " V2VsY29tZSB0byBCYXNoIENvb2tib29rCg==" | openssl enc -base64 -d
- Now we are going to encrypt and decrypt files. First, we will encrypt a file. Run the following command in the terminal:
$ openssl enc -aes-256-cbc -in /etc/services -out enc_services.dat
- Now we are going to decrypt a file. Run the following command in the terminal:
$ openssl enc -aes-256-cbc -d -in enc_services.dat > services.txt