Collections:
Other Resources:
OpenSSL "rsautl" - Encrypt Large File with RSA Key
How to encrypt a large file with an RSA public key using OpenSSL "rsautl" command?
✍: FYIcenter.com
If you are trying to use an RSA public key to encrypt a file larger than the key size directly, you will get the "data too large for key size" error.
One option to resolve the problem is to use the RSA-AES hybrid encryption process as described blow:
1. Generate a one-time random AES (Advanced Encryption Standard) symmetric encryption password shorter than the RSA public key. This can be done using the OpenSSL "rand n" command.
2. Encrypt the large input data with the AES algorithm using the short password. This can be done using the OpenSSL "enc -e -aes*" command.
3. Encrypt the short password with the RSA public key. This can be done using the OpenSSL "rsautl -encrypt" command.
4. Send the AES encrypted data and the RSA encrypted password to the owner of the public key.
For example:
C:\Users\fyicenter>type clear.txt The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. C:\Users\fyicenter>dir clear.txt 138 clear.txt C:\Users\fyicenter>\local\openssl\openssl.exe OpenSSL> pkey -pubin -in my_rsa_pub.key -text -noout Public-Key: (1024 bit) ... OpenSSL> rand 32 -out aes256_pass.txt OpenSSL> enc -e -aes256 -pass file:./aes256_pass.txt -in clear.txt -out cipher.txt OpenSSL> rsautl -encrypt -pubin -inkey my_rsa_pub.key -in aes256_pass.txt -out aes256_pass_cipher.txt
Commands used in this test:
You can publicly the AES encrypted data and the RSA encrypted password to the owner of the RSA public key. He/she can decrypt the AES password with his/her RSA private key, then decrypt the AES encrypted data with AES password.
⇒ OpenSSL "rsautl" - Decrypt Large File with RSA Key
⇐ OpenSSL rsautl "data too large for key size" Error
2017-06-07, 13🔥, 0💬
Popular Posts:
Certificate Summary: Subject: UTN - DATACorp SGC Issuer: UTN - DATACorp SGC Expiration: 2019-06-24 1...
Certificate summary - Owner: *.freelancer.com, Domain Control Validated - RapidSSL(R), See www.rapid...
What is the purpose of the OpenSSL "rsautl -sign" command? Can I use it to sign a document? Yes, you...
Key Summary: Type: RSA 2048-Bit Private Key Identifier: 50:1A:76:E1:F8:E5:2F:90: 8C:98:73:97:83:07:2A...
Certificate summary - Owner: COMODO Certification Authority, COMODO CA Limited, L=Salford, ST=Greate...