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-----.

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>
>
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> User Support Mailing List                    openssl-users@openssl.org
> Automated List Manager                           majord...@openssl.org

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

Reply via email to