There is currently a parsing bug when converting from PEM to DER. I encountered this as well, but with DSA keys. I suppose the same bug occurs with RSA keys.
In DSA the G component gets copied to the pub component when converting from PEM to DER. >From DER to PEM works fine. Regards, Dereck On Sun, Jan 5, 2014 at 8:49 PM, Alan D. Cabrera <l...@toolazydogs.com>wrote: > I've created a public key file using the following commands: > > openssl genrsa -out mykey.pem 2046 > openssl rsa -in mykey.pem -pubout > mykey.pub > > I then read it from some C code: > > public_key = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL); > > and then obtain the DER form of this public key: > > int len = i2d_RSAPublicKey (public_key, NULL); > buf = (unsigned char *) malloc (len); > i2d_RSAPublicKey (public_key, &buf); > here len == 269 > > but the command line openssl tells me: > > openssl rsa -outform der -pubin -inform pem -in mykey.pub | wc > writing RSA key > 1 10 293 > > When I print out the DER forms from openssl and my C code they, obviously, > don't match and, oddly, the DER encoding that my C code obtains has a lot > of zeros. > > What could I be doing wrong? > > > Regards, > Alan > > ______________________________________________________________________ > OpenSSL Project http://www.openssl.org > User Support Mailing List openssl-users@openssl.org > Automated List Manager majord...@openssl.org >