Hi, According to the man page, d2i_xx method is able to allocate memory for you. d2i_PUBKEY_xxx
If you are using OpenSSL 0.9.7 or later then this can be simplified to:
int len;
unsigned char *buf;
buf = NULL;
len = i2d_X509(x, &buf);
if (len < 0)
/* error */
But i think you have to free the memory using OPENSSSL_free().
Regards,
fred
-----Original Message-----
From: Edward Chan [mailto:[EMAIL PROTECTED]
Sent: Thu 7/21/2005 8:08 PM
To: [email protected]
Cc:
Subject: RE: d2i_RSAPublicKey doesn't work
Horray...that is it. Thanks!!!
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Edward Chan
> Sent: Thursday, July 21, 2005 11:00 AM
> To: [email protected]
> Subject: RE: d2i_RSAPublicKey doesn't work
>
> So I need to save buf to a tmp first like with d2i_RSAPublicKey?
>
> Like this:
>
> int len = i2d_RSAPublicKey(rsa, 0);
> unsigned char* buf = new unsigned char[len]; unsigned char*
> tmp = buf; i2d_RSAPublicKey(rsa, &tmp);
>
> // now use buf to decode
>
> Is this correct?
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Dr.
> > Stephen Henson
> > Sent: Thursday, July 21, 2005 10:23 AM
> > To: [email protected]
> > Subject: Re: d2i_RSAPublicKey doesn't work
> >
> > On Thu, Jul 21, 2005, Edward Chan wrote:
> >
> > > The code is basically like this:
> > >
> > > int len = i2d_RSAPublicKey(rsa, 0);
> > >
> > > // allocate buffer
> > > unsigned char* buf = new unsigned char[len];
> > >
> > > // now call again to DER encode the public key
> > > if (i2d_RSAPublicKey(rsa, &buf) == len)
> > > {
> > >
> > > I've also tried creating the RSA object first, and passing it into
> > > d2i_RSAPublicKey() for it to fill in. It also returns me
> null back.
> > > Does the code look right?
> > >
> >
> > No, this code is wrong for the reasons mentioned in the FAQ.
> > After this call 'buf' points to garbage and that's why
> > d2i_RSAPublicKey() is failing.
> >
> > 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]
> >
> ______________________________________________________________________
> OpenSSL Project http://www.openssl.org
> User Support Mailing List [email protected]
> Automated List Manager [EMAIL PROTECTED]
>
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [EMAIL PROTECTED]
<<winmail.dat>>
