Openssl is an open-source product used to implement the SSL protocol. It consists of three parts: cryptographic algorithm library, application program, and SSL protocol library. Openssl implements most of the algorithms required by the SSL protocol.
Next I will introduce how to use Openssl for symmetric encryption of files.
I. Openssl supports the following encryption algorithms:
-Aes-128-cbc-aes-128-cfb-aes-128-cfb1
-Aes-128-cfb8-aes-128-ecb-aes-128-ofb
-Aes-192-cbc-aes-192-cfb-aes-192-cfb1
-Aes-192-cfb8-aes-192-ecb-aes-192-ofb
-Aes-256-cbc-aes-256-cfb-aes-256-cfb1
-Aes-256-cfb8-aes-256-ecb-aes-256-ofb
-Aes128-aes192-aes256
-Bf-cbc-bf-cfb
-Bf-ecb-bf-ofb-blowfish
-Cast-cbc-cast5-cbc
-Cast5-cfb-cast5-ecb-cast5-ofb
-Des-cbc-des-cfb
Des-cfb1-des-cfb8-des-ecb
-Des-ede-cbc-des-ede-cfb
-Des-ede-ofb-des-ede3-des-ede3-cbc
Des-ede3-cfb-des-ede3-ofb-des-ofb
-Des3-desx-cbc
-Rc2-rc2-40-cbc-rc2-64-cbc
-Rc2-cbc-rc2-cfb-rc2-ecb
-Rc2-ofb-rc4-rc4-40
Ii. Openssl encryption command syntax:
SYNOPSIS
Openssl enc-ciphername [-in filename] [-out filename] [-pass arg] [-e]
[-D] [-a] [-A] [-k password] [-kfile filename] [-K key] [-iv IV] [-p]
[-P] [-bufsize number] [-nopad] [-debug]
Note:
-Chipername option: encryption algorithm. The Algorithms supported by Openssl are listed above. You only need to select one of them to implement file encryption.
-In option: indicates the input file. For encryption, the input file should be a plaintext file; for decryption, the input file should be an encrypted file. This option is followed by the file name.
-Out option: output file. For encryption, the output should be the encrypted file name; for decryption, the output should be the plaintext file name.
-Pass option: select the password input method. The input source can be a standard input device, command line input, files, variables, and so on.
-E Option: implements the encryption function (if the-d option is not used, the encryption option is used by default ).
-D option: Implements decryption.
-A and-A options: Perform BASE64 encoding/Decoding on the file.
-K option: Enter the encryption key manually. (If this option is not used, Openssl uses a password to automatically extract the encryption key ).
-IV option: Enter the initial variable. (If this option is not used, Openssl uses a password to automatically extract the initial variable ).
-Salt option: whether to use the salt value. It is used by default.
-P option: print the encryption key used by the encryption algorithm.
Iii. cases:
1. Use the aes-128-cbc algorithm to encrypt files:
Openssl enc-aes-128-cbc-in install. log-out enc. log
(Note: Here install. log is the file you want to encrypt, and enc. log is the encrypted file. After you press enter, the system will prompt you to enter the password)
2. decrypt the encrypted file:
Openssl enc-d-aes-128-cbc-in enc. log-out install. log
(Note: enc. log is the encrypted file, install. log is the decrypted file, and-d option implements the decryption function)
3. The encrypted file is encoded in BASE64 format:
Openssl enc-aes-128-cbc-in install. log-out enc. log-
4. encryption using multiple password input methods:
Openssl enc-des-ede3-cbc-in install. log-out enc. log-pass: 111111
(The advantage of this method is that you can write it into the script to automatically complete the encryption function. If you do not use the pass option, the system will prompt you to enter the password by default and confirm that it requires manual operation)
4. Openssl functions are far more than that. If you are interested, refer to the Openssl manual. In Linux, you can use man openssl to quickly obtain help files.
For example, the file file.tar.gz is encrypted with a password of 123456.
Openssl des3-salt-k 123456-in file.tar.gz-out file.tar.gz. des3
Decrypt file.tar.gz. des3
Openssl enc-des3-d-in file.tar.gz. des3-out file.tar.gz
This article is from the "wind" blog