How to do it...

  1. 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
  1. To decrypt the message, run following command in the terminal:
$ echo " V2VsY29tZSB0byBCYXNoIENvb2tib29rCg==" | openssl enc -base64 -d
  1. 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
  1. 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

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.