OpenSSL: Public-Private Key Encryption

Generate private key

First, you need a private key to generate a public key.

openssl genrsa -out privatekey.pem 2048

Generate public key

openssl rsa -in privatekey.pem -pubout -out publickey.pem

Encrypt using public key

echo "hello" > hello.txt
openssl pkeyutl -encrypt -inkey publickey.pem -pubin -in hello.txt -out hello.txt.enc

Decrypt using private key

openssl pkeysutl -decrypt -inkey private.pem -in hello.txt.enc -out hello.txt

Comments

Leave a Reply

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