Skip to content

Instantly share code, notes, and snippets.

@Aurora12
Last active May 10, 2023 09:13
Show Gist options
  • Save Aurora12/4c20ef4e1aa12aab2a257786b1669d37 to your computer and use it in GitHub Desktop.
Save Aurora12/4c20ef4e1aa12aab2a257786b1669d37 to your computer and use it in GitHub Desktop.
Basic openssl encrypt-decrypt with RSA
# Generate a private key
# Note: RSA can only encrypt messages that have fewer bits than the key.
openssl genrsa -des3 -out ./private4096.pem 4096
# Export public key
openssl rsa -in ./private4096.pem -outform PEM -pubout -out ./public4096.pem
# Encrypt
openssl rsautl -encrypt -inkey ./public4096.pem -pubin -out ./ciphertext.$(date +'%Y-%m-%d_%H-%M-%S') -in ./plaintext.file
#Decrypt
openssl rsautl -decrypt -inkey ./private4096.pem -in ./ciphertext.file > plaintext.$(date +'%Y-%m-%d_%H-%M-%S')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment