> From: owner-openssl-us...@openssl.org On Behalf Of Graham Leggett > Sent: Friday, 16 November, 2012 10:08 > To: openssl-users@openssl.org > Subject: Re: Usage of d2i_RSA_PUBKEY function!! > > On 16 Nov 2012, at 4:37 PM, PraveenPVS > <meetpraveen...@gmail.com> wrote: > > > I need to load RSA Public key which is stored in the char > buffer. I came > > across d2i_RSA_PUBKEY function to do the same (Please > correct me if I am > > wrong here). > > The "d2i" in the function you're trying to use means "from > DER encoded to internal", you'll see a whole lot of > complementary functions with "i2d" in them that do the opposite. > > The data you've shown looks like it has been PEM encoded, not > DER encoded: > > > > loadRSAPubKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0ye > pYbVklwYuwGEmenQhVwyddHGdM26rZqWG5tFFPYz1QA51EJ44thSejrbRKHqV/ > EmqU8wwuFeaDmxnVz6UhG3HfjuTbAkkuZ+boEIealr/Ml+kHqRgzQ6G1rP9+5g oboZzlpB9b8zYvp+> 5my5xFCd8OqyoKKyoHBJ3Tf0NCSstow7k0W/5JMeDa844HpCK4rOxlUaIGsDGT > C/XIJ93EQs8yT4js5iw++pJslQvh1RzeQtzLQ8xNGYKlr9RyIvh2S28qXb+qfE > x7r+kG8RjS4jc3E3XR/nja7HXnAFWCgF/cRcj5aQHq02scW8Vi+iBS/A1Y5RD2 > QMxJqY1yxC28QIDAQAB"); > > To convert the PEM encoding, try wrap your buffer in a BIO > and call PEM_read_bio_X509(). "man PEM_read_bio_X509" for > details. Make sure you preserve the "-----" bars before and > after the PEM encoded certificate, as they form part of the > PEM encoding and your data may be ignored if you chop them off.
Those need to be dashes-BEGIN and END *lines* before and after, and you also must keep line breaks in the body. b64BIO by default rejects base64 lines longer than the traditional PEM/MIME limit (somewhere around 76-80, I don't remember exactly). For an explicit b64BIO you can control this, but not within PEM_read*. Alternatively, convert the base64 to binary (EVP_DecodeBlock *doesn't* enforce the line length limit) and use d2i_*. ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org