Hello,
> Hi!
> 
> I tired to use RSA encryption.
> 
> 
> unsigned char *rsa_in = "Very secret message Very secret message Very secret 
> m";
> 
> OpenSSL_add_all_algorithms();
> pad = RSA_PKCS1_PADDING;
> rsa_inlen = strlen(rsa_in);
> printf ("rsa_inlen:%d\n",rsa_inlen);
> 
> rsa = RSA_generate_key(512,RSA_F4,NULL,NULL);
> keysize = RSA_size(rsa);
> printf ("Keysize:%d\n",keysize);
> rsa_out = OPENSSL_malloc(keysize);
> 
> rsa_outlen  = RSA_public_encrypt(rsa_inlen, rsa_in, rsa_out, rsa, pad);
> printf ("rsa_outlen:%d\n",rsa_outlen);
> }//end
> 
> output :
> rsa_inlen:53
> Keysize:64
> rsa_outlen:64
> 
> is good, but if:
> unsigned char *rsa_in = "Very secret message Very secret message Very
> secret me";
> ......
> 
> rsa_inlen:54
> Keysize:64
> rsa_outlen:-1

> why? rsa_inlen is 53: working correctly
> rsa_inlen is 54 or above: segmentation fault.
You generated 512 bit key (64 bytes) so you can encrypt
without padding max 64 bytes.
Because you specified RSA_PKCS1_PADDING padding witch requires
minimum 11 bytes of free space than you can encrypt max 53 bytes
with this type of padding (your data is first padded and than
encrypted).

> how to do RSA encrypt with very long string, or with file???
Usually only session keys, shared keys and this type of data
is encrypted with RSA ... usually :-)

Best regards,
-- 
Marek Marcola <[EMAIL PROTECTED]>

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [email protected]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to