Generate Alice's RSA key pair (2048-bit)
openssl genrsa -out alice_private.pem 2048
Extract Alice's public key from her private key
openssl rsa -in alice_private.pem -pubout -out alice_public.pem
Bob creates a message and encrypts it with Alice's public key
echo "Secret message from Bob" > bob_message.txtopenssl rsautl -encrypt -inkey alice_public.pem -pubin -in bob_message.txt -out encrypted_to_alice.bin
Alice decrypts Bob's message with her private key
openssl rsautl -decrypt -inkey alice_private.pem -in encrypted_to_alice.bin -out decrypted_from_bob.txt
Generate Bob's RSA key pair
openssl genrsa -out bob_private.pem 2048
Extract Bob's public key and Alice encrypts a reply
openssl rsa -in bob_private.pem -pubout -out bob_public.pemecho "Reply from Alice" > alice_reply.txtopenssl rsautl -encrypt -inkey bob_public.pem -pubin -in alice_reply.txt -out encrypted_to_bob.bin
Bob decrypts Alice's reply with his private key
openssl rsautl -decrypt -inkey bob_private.pem -in encrypted_to_bob.bin -out decrypted_from_alice.txt
Try decrypting with the wrong key to see failure
openssl rsautl -decrypt -inkey bob_private.pem -in encrypted_to_alice.bin -out wrong.txt