Skip to content

Encryption and Decryption with RSA key pair

generate a RSA key pair

openssl genpkey -algorithm RSA -out private_key.pem
openssl rsa -pubout -in private_key.pem -out public_key.pem

encrypt

assuming the file you want to encrypt is test.txt, and the output encrypted file is encrypted_test.txt

openssl rsautl -encrypt -pubin -inkey public_key.pem -in test.txt -out encrypted_test.txt

decrypt

openssl rsautl -decrypt -inkey private_key.pem -in encrypted_test.txt -out decrypted_test.txt
Leave a Reply