I'm sorry it took me so long to test this...but here's the result:

I'm still getting an error when trying to read this key using the BIO
interface:

Error: error:0906D064:PEM routines:PEM_read_bio:bad base64 decode

More info below:

My pubkey looks like this (this is just a test key):
(pubkey.h):
static const char* pubkey = (char*)"\
-----BEGIN PUBLIC KEY-----\n\
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAo+0cqJqlbJ7IoauOQzS\
wm43nMeM1wgapDxhgeNxBFz8Y8WdC56iHu7ICQhrIybzK1Zv1a9dmExyeGhGPRM\
vXYssNoOhphLFiN5mUwA3BNkxY2QwECESqPnlThXGiJ4bhBwvdXJ8ixtjGIh84P\
BV70Hf1F+FfVQPbi7GctLWSx6JD5xLb9h5D0sdfierup0TfNDMgrVDwvIlG4iKe\
GfB8npCUcicQ1E8pqx1axX3OxHIRr0dLIPrsPWKVj24jdeDZn0H+jhKxqus2/Yv\
fdoPAnlKgltmlnon23C06hziIOwbvECDho9zrw+nQSWQIQvs1TXaSZjYgVM45Uk\
zFNYn2Smv0efCUPEJa6gNawR/HFw8hIpBmtl6Jhm+du9AgLGU0j4pgAcw0xfj5F\
vsjeZfQDHm9FIbhY9dOoqcCwoIV5gzsb224T2uIHc+glAPjCOS+3rEP1+YwcGIK\
ObtIbzq2/rxS1HEx5z4NacLToOFZSKStgshXFQIjWCJ+2dCS8I4z5rkn1cP4bNR\
RIB7J5gdOsq+NJuLjC42QfTW7+rq/9ivjAUPwbnytqfWITbJZB5RurumCnaURqb\
18v6kzvjO0A3Hxk2a1zjbpsO1+w9G3dW/F0fWqfn2JQoCTXKf1FJnzN+NaRMa5a\
vt8ohOwbObEDRoEjaC/OqiERaX4pHrHhU8CAwEAAQ==\n\
-----END PUBLIC KEY-----\n\
";

My code to read the pubkey looks like this:

BIO* bio = BIO_new_mem_buf((void*)pubkey, -1);
RSA* x = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL);

The results of this action are:
Error: error:0906D064:PEM routines:PEM_read_bio:bad base64 decode

What is wrong with this key?

-Zach

On 04/02/2013 03:03 AM, Jakob Bohm wrote:
> On 02-04-2013 00:30, Zach wrote:
>> I've been reading through the OpenSSL documentation, but I must be
>> missing something...
>>
>> I have a public key (base64 encoded) which looks something like this:
>> MIICIjANBgkqhkiG9w0BAQEFA......U8CAwEAAQ==
>> This is in a char buffer.  I've tried this with/without the wrapping
>> text of -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY-----.
> Did you remember to put "\n" after the two marker strings and before
> the end string?
>
> "-----BEGIN PUBLIC KEY-----\n" and "\n-----END PUBLIC KEY-----\n"
>
>> I then do the following 2 lines of code:
>> BIO* bio = BIO_new_mem_buf((void*)pubkey, -1);
>> RSA* x = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL);
>>
>> As I understand it, this should:
>> 1) create a BIO wrapper around the char* pubkey source, and
>> 2) read from this BIO pointer an RSA key.
>>
>> However, the RSA pointer is null, and when I check the errors coming out
>> of the library it says:
>> error:0906D06C:PEM routines:PEM_read_bio:no start line
>>
>> I assume that I've formed the BIO instance incorrectly...what should I
>> do differently?
>>
>> -Zach
>>
>> On 03/31/2013 02:49 AM, Dave Thompson wrote:
>>>> From: owner-openssl-us...@openssl.org On Behalf Of Felipe Blauth
>>>> Sent: Friday, 29 March, 2013 16:36
>>>> To read the key from your header file you might want to use
>>>> a memory BIO in conjunction with the PEM_read_bio_PUBKEY function
>>>> or PEM_read_bio_RSAPublicKey ( I don't remember which one you should
>>>> use, but this was answered in this list before). I don't have a test
>>> The default from commandline is PUBKEY (*private* keys changed
>>> from per-algorithm to PKCS8 in 1.0.0).
>>>
>>>> enviroment right now, but you should do something like this:
>>>> char key[] = "Your pem key goes here";
>>> Including newlines represented as \n, which is easy to miss.
>>>
>>>> BIO *mem = BIO_new(BIO_s_mem());
>>>> BIO_puts(mem, key);
>>> Or just BIO_new_mem_buf(key,len_or_neg1);
>>>
>>>> EVP_PKEY* pkey=PEM_read_bio_PUBKEY(mem,NULL,NULL,NULL);
>>> Or PEM_read_bio_RSA_PUBKEY to "downcast" to RSA*, which you can
>>> also do separately, but EVP is generally preferable.
>>>
>>> <snip>
>>>
>
> Enjoy
>
> Jakob

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to