Vannkorn

Full Stack Web Developer

Close

Symmetric and Asymmetric Cryptography Commands

Useful for the comprehensive understanding of the Cryptography in general.

Ads: Register now via this link to receive $300 credit from Vultr

I’ve just cam across a basic tutorial about the Symmetric and Asymmetric Cryptography commands I found useful for the comprehensive understanding of the Cryptography in general.

Symmetric Cryptography

Is a one-way encrypted-decrypted method.

To encrypt:

$openssl aes-128-ecb -e -in sample.txt -out encrypted.txt

Where aes-128-ecb is the name of the algorithm. To find out what algorithm available, just type $openssl list -cipher-algorithms

To decrypt:

$openssl aes-128-ecb -d -in encrypted.txt

Asymmetric Cryptography

This is a two-way algorithm that need a Private Key and a Public Key to operate. Basically, it needs a Public Key to encrypt and a Private Key to decrypt.

To generate a Private Key:

$openssl genrsa -out private.pem 1024

Where <code>genrsa</code> is the algorithm and <code>1024</code> is the length of the text/content it generates.

To generate a Public Key based on the Private Key:

$openssl rsa -in private.pem -pubout -out public.pem -outform PEM

To encrypt:

$openssl pkeyutl -encrypt -inkey public.pem -pubin -in sample.txt -out encrypted.txt

To decrypt:

$openssl pkeyutl -decrypt -inkey private.pem -in encrypted.txt -out decrypted.txt

Here we create a new file to store the decrypted content called decrypted.txt.

Leave a Reply

Your email address will not be published. Required fields are marked *