File encryption using OpenSSL
This article contains step by step approach for encrypting files using AES with OpenSSL.

What is OpenSSL?
Open SSL can be identified as a general-purpose cryptography package that provides the open-source application of TLS protocol. It is available for Linux, Windows, macOS, and BSD platforms, and was first released in 1998.
There is a high demand for SSL certificates as the encryption landscape has changed considerably due to Google’s “HTTPS Everywhere” campaign. They first gave an SEO boost as an encouragement to install digital signatures. and then Chrome declared HTTPS is necessary for everyone. Popular browsers such as Chrome and Firefox will label your site as Not Secure if you don’t use an SSL certificate. SSL deployment is critical to the safety and success of a website. And, because so many people are learning about SSL for the first time, it’s crucial to provide them with all of the necessary tools and services. OpenSSL is one such utility.
Users can use OpenSSL to accomplish a variety of services including generating private keys, creating CSRs, installing your SSL/TLS certificate, and identifying certificate information.
What is AES?
AES is a symmetric method of encryption since it encrypts and decrypts data using the same key.
It also utilizes the SPN (substitution permutation network) method, which encrypts data in several rounds. Because there are simply too many rounds to get through, these encryption rounds are the reason for AES’ inscrutability.
AES encryption keys come in three different lengths. There is indeed a distinct number of possible key combinations for each key length:
- The length of a 128-bit key is 3.4 x 1038 bits
- The length of a 192-bit key is 6.2 x 1057 bits
- The length of a 256-bit key is 1.1 x 1077 bits
Even though the encryption method’s key length varies, the block size — 128 bits (or 16 bytes) — remains constant.
Let’s get started…
3DES or AES symmetric key encryption on a text file
- Open the terminal
- Encrypt the relevant file using the following command
openssl enc –aes-256-cbc –in <filename.fileextension> -out <encryptedfilename.fileextension>
Example:
openssl enc –aes-256-cbc –in sslabs1.txt -out ensslabs1.txt

RSA asymmetric key encryption on a text file
- Open the terminal
- For Asymmetric encryption firstly we must generate the private key and extract the public key.
openssl genrsa -aes256 -out private.key 2025openssl rsa -in private.key -pubout -out public.key
3. Encryption
openssl rsautl -encrypt -pubin -inkey public.key -in sslabs1.txt –out en_rsa_sslabs1.txt
4. Decryption
openssl rsautl -decrypt -inkey private.key -in en_rsa_sslabs1.txt –out decrypted_sslabs1.txt
