OpenSSL "rsautl -encrypt" - Encryption with RSA Public Key


How to encrypt a file with an RSA public key using OpenSSL "rsautl" command?



If you want to encrypt a file with an RSA public in order to send private message to the owner of the public key, you can use the OpenSSL "rsault -encrypt" command as shown below:

C:\Users\fyicenter>type clear.txt
The quick brown fox jumped over the lazy dog.

OpenSSL> rsautl -encrypt -pubin -inkey my_rsa_pub.key -in clear.txt 
   -out cipher.txt
OpenSSL> exit

C:\Users\fyicenter>dir *.txt
   128 cipher.txt
    45 clear.txt

Options used in the "rsautl" command are:

  • "-encrypt" - Encrypt the input data with RSA keys.
  • "-pubin" - Use RSA public key.
  • "-inkey my_rsa_pub.key" - Read RSA key, the public key, from the given file.
  • "-in clear.txt" - Read input data, the clear text, from the given file.
  • "-out cipher.txt" - Save output data, the cipher text, to the given file.

Note that the encrypted data, cipher.txt, can only be decrypted by the owner of the public key with his/her matching private key.


OpenSSL "rsautl" Command for RSA Keys

⇒⇒OpenSSL Tutorials

2017-06-11, 471👍, 0💬