Home >System Tutorial >LINUX >How to use OpenSSL to encrypt and decrypt files
1. Use openssl to encrypt a file (data.zip is the original file, back.zip is the encrypted file)
# openssl enc -e -aes256 -in data.zip -out back.zip
Explanation: enc means symmetric encryption or decryption of files, -e means encryption of a file, -aes256 means encryption using the aes256 algorithm, -in means the file that needs to be encrypted, -out means the file generated after encryption new file. During the encryption process, you will be asked to enter an encryption password. Enter it twice to complete the encryption of the file
2. Use openssl to decrypt a file (back.zip is the encrypted file, data.zip is the decrypted file)
# openssl enc -d -aes256 -in back.zip -out data.zip
Explanation: enc means symmetric encryption or decryption of the file, -d means decryption of the file, -aes256 means decryption using the aes256 algorithm, -in means the file that needs to be decrypted, -out means the new file generated after decryption file, when decrypting a file, you will be asked to enter the password set when encrypting the file to decrypt it.
1. First you need to use openssl to generate a 2048-bit key rsa.key file (rsa.key key file contains the private key and public key)
# openssl genrsa -out rsa.key 2048
2. Then extract the public key pub.key
from the rsa.key key file# openssl rsa -in rsa.key -pubout -out pub.key
3. Use the pub.key public key to encrypt a file (data.zip is the original file, back.zip is the encrypted file)
# openssl rsautl -encrypt -inkey pub.key -pubin -in data.zip -out back.zip
4. Use the rsa.key private key to decrypt a file (back.zip is the encrypted file, data.zip is the decrypted file)
# openssl rsautl -decrypt -inkey rsa.key -in back.zip -out data.zip
Finally, we use the OpenSSL tool to encrypt and store all backup data files to ensure that the business system data is protected and leaked. We can also use other encryption tools such as GPG, VeraCrypt, and trueCrypt to encrypt data, but in comparison, using OpenSSL is more convenient because almost every Linux distribution comes with the OpenSSL software package pre-installed.
The above is the detailed content of How to use OpenSSL to encrypt and decrypt files. For more information, please follow other related articles on the PHP Chinese website!