Encrypting and Decrypting data using SSL Key


First generate the RSA key (key.pem):

openssl genrsa -out key.pem 4096
openssl rsa -in key.pem -text -noout 

 

Then save the public key in pub.pem:

openssl rsa -in key.pem -pubout -out pub.pem 
openssl rsa -in pub.pem -pubin -text -noout 

 

As an example we're creating a simple text file and encrypt it:

echo test12345 > file.txt 
openssl rsautl -encrypt -inkey pub.pem -pubin -in file.txt -out file.bin

 

Decrypting the file:

openssl rsautl -decrypt -inkey key.pem -in file.bin