On Sat, May 19, 2007, belguechi rima wrote:
> Hello;
>
> I have compiled the source code from the version OpenSSL 0.9.8e. Now I am
> trying to use the libraries generated in the following program portion :
>
>
> RSA *rsa=NULL;
> RSA *ConstructedRSA = NULL;
>
> unsigned char *pvk_buf, *p ;
> int pvk_len;
>
>
> ERR_load_crypto_strings();
> rsa = RSA_new();
> ConstructedRSA = RSA_new();
> rsa = RSA_generate_key(1024, RSA_F4, NULL, NULL);
> if (rsa == NULL)
> {
> ERR_print_errors_fp(stderr);
> exit(1);
> }
> result = RSA_check_key(rsa);
> if (result <= 0)
> {
> ERR_print_errors_fp(stderr);
> exit(1);
> }
> pvk_len = i2d_RSAPrivateKey(rsa, NULL);
> if(pvk_len>0){
> pvk_buf = (unsigned char *)malloc(pvk_len);
> memset(pvk_buf,0,pvk_len);
> p = pvk_buf;
> i2d_RSAPrivateKey(rsa, &p);
>
> ConstructedRSA = d2i_RSAPrivateKey(NULL, (const unsigned char **)&p,
> pvk_len);
>
> The problem is that the buffer p don't contain any values for the rsa key.
> So, what is wrong ?
>
As indicated in the FAQ after the i2d call p is incremented to pointer after
the buffer. So you need to set p = buf again after the i2d call.
Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Funding needed! Details on homepage.
Homepage: http://www.drh-consultancy.demon.co.uk
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [EMAIL PROTECTED]