Skip to content

Instantly share code, notes, and snippets.

@garystafford
Last active February 9, 2021 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garystafford/0e22315039f2bf12a86c871a1a6629c8 to your computer and use it in GitHub Desktop.
Save garystafford/0e22315039f2bf12a86c871a1a6629c8 to your computer and use it in GitHub Desktop.
# public-key cryptography demo for Mac or Linux
# create the private key - require a pass phrase
# openssl genrsa -aes256 -out sec-cert.pem 2048
# create the private key - no pass phrase required
openssl genrsa -out sec-cert.pem 2048
# create public key (PEM)
openssl rsa -in sec-cert.pem -outform PEM -pubout -out sec-cert.pub.pem
echo "This is a message that will be encrypted with my public key..." >> myMessage.txt
# encrypt the text file
openssl rsautl -encrypt -pubin -inkey sec-cert.pub.pem -oaep -in myMessage.txt -out myEncryptedMessage.txt
cat myEncryptedMessage.txt
# decrypt the text file
openssl rsautl -decrypt -inkey sec-cert.pem -oaep -in myEncryptedMessage.txt -out myDecryptedMessage.txt
cat myDecryptedMessage.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment