Hmm, well, I guess I assumed i2d_RSAPublicKey() was ok since the RSA key
seems fine (I ran RSA_check_key() on it and it says it is ok).  Is there
any reason why i2d_RSAPublicKey() would not be returning me valid data?

int len = i2d_RSAPublicKey(rsa, 0);

returns me something > 0, so I assumed that it is fine.  Wouldn't this
return -1 if it failed?

I am using the RSA_public_encrypt and RSA_private_decrypt functions
because that is what I found in the OpenSSL book I've been using as a
reference.  Should I be using something else? Is there an alternative to
the i2d* methods for converting the public and private portions of the
RSA key to some serializable form?

As for the usage of i2d_RSAPublicKey(), it is as the book says.  I call
it once to find the size of the buffer required.  Then I allocate the
buffer.  Then call it again to actually fill the buffer.  Is this not
correct?

Thanks,
Ed 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Dr. 
> Stephen Henson
> Sent: Wednesday, July 20, 2005 5:48 PM
> To: openssl-users@openssl.org
> Subject: Re: d2i_RSAPublicKey doesn't work
> 
> On Tue, Jul 19, 2005, Edward Chan wrote:
> 
> > That part of the code remains the same, and continues to 
> work fine.  
> > By the way, my last code snippet should have been:
> > 
> > U8* tmp = buf;
> > RSA* pub = d2i_RSAPublicKey(0, (const U8**)&tmp, len);
> > 
> > I mistakenly typed *len instead of len.
> > 
> > Anyways, after I call i2d_RSAPublicKey, calling 
> d2i_RSAPublicKey does 
> > not seem to work. It always returns me a null ptr.  But I 
> know the RSA 
> > object is fine.  I can use it in RSA_public_encrypt() and 
> > RSA_private_decrypt().
> > 
> 
> What makes you think the way i2d_RSAPublicKey is being called 
> is producing valid data? Try dumping the data in 'tmp' to a 
> file and using:
> 
> openssl asn1parse -inform DER -in whatever
> 
> if the result is an error message or what looks like garbage 
> then its a problem with the usage of i2d_RSAPublicKey. If it 
> looks like the public key components then it is OK.
> 
> BTW is there some reason you are using the RSAPublicKey 
> functions? If you use the RSA_PUBKEY versions instead the 
> OpenSSL utilities will be able to check the format directly.
> 
> 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                    openssl-users@openssl.org
> Automated List Manager                           [EMAIL PROTECTED]
> 
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to