Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use openssl to encrypt and decrypt files

Shulou Source: shulou.com Published: 2022-06-01 13:41:28 09月12日 Update

This article mainly introduces how to use openssl to encrypt and decrypt files, the article is very detailed, has a certain reference value, interested friends must read it!

Openssl is a secure socket layer password library, including the main cryptographic algorithms, common keys, certificate encapsulation management functions and the implementation of ssl protocol. The whole software package of OpenSSL can be divided into three main functional parts: SSL protocol library libssl, application command tool and cryptographic algorithm library libcrypto.

OpenSSL uses passwords to encrypt or decrypt files

\ 1. Encrypt a file using openssl (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 to encrypt or decrypt a file symmetrically,-e means to encrypt a file,-aes256 means to encrypt a file using the aes256 algorithm,-in indicates a file that needs to be encrypted, and-out represents a new file generated after encryption. In the process of encryption, you will be required to enter an encryption password, which can be repeated twice to complete the encryption of the file.

\ 2. Decrypt a file using openssl (back.zip is encrypted file, data.zip is decrypted file)

# openssl enc-d-aes256-in back.zip-out data.zip

Explanation: enc means to encrypt or decrypt the file symmetrically,-d means to decrypt the file,-aes256 means to decrypt the file using the aes256 algorithm,-in indicates the file that needs to be decrypted, and-out indicates the new file generated after decryption. When decrypting a file, you will be required to enter the password set when the encrypted file can be decrypted.

* * OpenSSL uses keys to encrypt or decrypt files

**

\ 1. First, you need to use openssl to generate a 2048-bit key rsa.key file (rsa.key key file contains private and public keys)

# 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. Encrypt a file using the pub.key public key (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. Decrypt a file using the rsa.key private key (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 the backed-up data files, which can ensure the protection of business system data and prevent leakage. We can also use other encryption tools such as GPG,VeraCrypt,trueCrypt to encrypt data, but it is more convenient to use OpenSSL because almost every Linux distribution comes with an OpenSSL package.

The above is all the contents of the article "how to encrypt and decrypt files using openssl". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Files encryption passwords keys tools public keys data algorithms generation input original symmetry content functions methods articles software packages interpretations security Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MySQL MariaDB Shulou Tech Info Shulou Information