RSA Public Key / Private Key Encryption with OpenSSL

RSA Public Key / Private Key Encryption with OpenSSL

You can do RSA (and DSA actually) on most unix systems without any additional software… No GPG/PGP required. It’s less than obvious however, as I couldn’t find any documentation that puts this all in one place. So here it is…

Generate a new private key:

openssl genrsa -out test.priv_key

Generate the public key for this private key:

openssl rsa -in test.priv_key -pubout -out test.pub_key

RSA encrypt a block:

openssl rsautl -sign -inkey test.priv_key -pkcs -out test.sig

Decrypt an RSA block:

openssl rsautl -verify -in test.sig -inkey test.pub_key -pubin

You can also sign a block using MD5:

openssl md5 | openssl rsautl -sign -inkey test.priv_key -pkcs -out test.sig

Share on facebook
Share on twitter
Share on linkedin
Share on print
Share on email