- Linux Shell Scripting Cookbook(Third Edition)
- Clif Flynt Sarath Lakshman Shantanu Tushar
- 288字
- 2021-07-09 19:46:19
How to do it...
Let's see how to use tools such as crypt, gpg, and base64:
- The crypt command is not commonly installed on Linux systems. It's a simple and relatively insecure cryptographic utility that accepts input from stdin, requests a passphrase, and sends encrypted output to stdout:
$ crypt <input_file >output_file Enter passphrase:
We can provide a passphrase on the command line:
$ crypt PASSPHRASE <input_file >encrypted_file
In order to decrypt the file, use this:
$ crypt PASSPHRASE -d <encrypted_file >output_file
- gpg (GNU privacy guard) is a widely used tool for protecting files to ensure that data is not read until it reaches its intended destination.
gpg signatures are also widely used in e-mail communications to "sign" e-mail messages, proving the authenticity of the sender.
In order to encrypt a file with gpg, use this:
$ gpg -c filename
This command reads the passphrase interactively and generates filename.gpg. In order to decrypt a gpg file, use the following command:
$ gpg filename.gpg
This command reads a passphrase and decrypts the file.
We are not covering gpg in much detail in this book. For more information, refer to http://en.wikipedia.org/wiki/GNU_Privacy_Guard.
- Base64 is a group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. These programs are used to transmit binary data via e-mail. The base64 command encodes and decodes the Base64 string. To encode a binary file into the Base64 format, use this:
$ base64 filename > outputfile
Alternatively, use this command:
$ cat file | base64 > outputfile
It can read from stdin.
Decode Base64 data as follows:
$ base64 -d file > outputfile
Alternatively, use this:
$ cat base64_file | base64 -d > outputfile