With RSA, the data to be encrypted is first mapped on to an integer. For RSA to work, this integer must be smaller than the RSA modulus used. In order to get things to work the way you want, if you are using a (say) 1,024-bit RSA modulus, you must split your input data in chunks 1,024 bits long, at most. Actually, if using padding, which you you should, they've got to be even smaller - e.g. 11 bytes smaller for PKCS #1 v1.5 padding. You then would have to encrypt each chunk sequentially, using a mode like ECB or CBC.

   Having said all that, you should not proceed that way. RSA encryption/decryption is tremendously slow and CPU intensive. You'd be far better off encrypting your big input file with some symmetric algorithm (e.g. AES) and then encrypting with the RSA key (private or public, depending on your needs) the key used with this algorithm.


On 12/11/05, Amir (sent by Nabble.com) <[EMAIL PROTECTED]> wrote:
Hi all,

How can I encrypt a large file (like 100mb) with a public key so that no one other than who has the private key be able to decrypt it?

I can make RSA public and private keys but when it comes to encrypting a large file using this command:

openssl rsautl -encrypt -pubin -inkey public.pem -in myLargeFile.txt -out myLargeFile_encrypted.txt

I get this error:

RSA operation error
3020:error:0406D06E:rsa routines:RSA_padding_add_PKCS1_type_2:data too large for key size:.\crypto\rsa\rsa_pk1.c:151:

I tried to make keys with sizes from 40 to 4096 bits, no luck, same error

Thankx in advance

Amir



Sent from the OpenSSL - User forum at Nabble.com:
How to encrypt a large file by a public key?

Reply via email to