If you're referring to http://www.openssl.org/support/faq.html
3. How do I read or write a DER encoded buffer using the ASN1 functions? ... The opposite assumes we already have len bytes in buf: unsigned char *p; p = buf; p7 = d2i_PKCS7(NULL, &p, len); At this point p7 contains a valid PKCS7 structure of NULL if an error occurred. If an error occurred ERR_print_errors(bio) should give more information. The reason for the temporary variable 'p' is that the ASN1 functions increment the passed pointer so it is ready to read or write the next structure. This is often a cause of problems: without the temporary variable the buffer pointer is changed to point just after the data that has been read or written. This may well be uninitialized data and attempts to free the buffer will have unpredictable results because it no longer points to the same address. ------------------------------------------------------ I see where it says you need to create the temp var. So changed my code to do that, but I still get a null ptr returned. Code is now: U8* tmp = buf; RSA* pub = d2i_RSAPublicKey(0, (const U8**)&tmp, *len); > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Nils Larsch > Sent: Monday, July 18, 2005 1:10 PM > To: openssl-users@openssl.org > Subject: Re: d2i_RSAPublicKey doesn't work > > Edward Chan wrote: > > What am I doing wrong here? I generate an RSA key. Then I > DER encode > > it. Then try to decode it, but the decode fails. The error says, > > "error:0D07207B:asn1 encoding > routines:ASN1_get_object:header too long" > > > > RSA* rsa = RSA_generate_key(2048, RSA_F4, 0, 0); if (rsa) { > > if (RSA_check_key(rsa) > 0) > > { > > int len = i2d_RSAPublicKey(rsa, 0); > > > > U8* buf = new U8[len]; > > memset(buf, 0, len); > > > > i2d_RSAPublicKey(rsa, &buf); > > > > // everything looks good up to here; I can see buf > > gets filled with len number of bytes > > // but then I try to get the public key > back by doing > > the following, and it fails. > > > > RSA* public_key = d2i_RSAPublicKey(0, (const > > U8**)&buf, len); // public_key is NULL; why??? > > if (!public_key) > > { > > char err[1024]; > > ERR_error_string(ERR_get_error(), err); > > fprintf(stderr, "Error : %s\n", err); > > } > > } > > } > > please read the FAQ > > Nils > > ______________________________________________________________________ > 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]