[help] how to load the privatekey from char[] = "MIICxjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9..."

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[help] how to load the privatekey from char[] = "MIICxjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9..."

구제성
Samsung Enterprise Portal mySingle

Hi, I'm jaesung ku and incorporated with samsung elecs.

 

While using the openssl, I have the XXprivatekey.pem file.

I can load the privatekey through the functions below.

--------------

BIO *key=NULL;

key=BIO_new(BIO_f_buffer());

BIO_read_filename(key, XXprivatekey.pem filepath);

pkey = PEM_read_bio_PrivateKey(key, NULL, NULL, (void *)pass);

--------------

 

Now I'm trying to replace the filepath with char[] which has all characters of the file.

But, as you expect, it does not work.

 

I think that in order to use the char[], BIO_new(BIO_METHOD type) should be appropriate for char[].

So far, I can't find the solution.

 

Can you help me?

 

Thanks for your help in advance.

Best regards,

 

Jaesung Ku

 

Jaesung Ku | Engineer
Mobile : +82-10-3818-3499

E-Mail : [hidden email]

SAMSUNG ELECTRONICS CO.,LTD

S/W Platform Group

Platform R&D Team
Mobile Communication Division

 

Reply | Threaded
Open this post in threaded view
|

Re: [help] how to load the privatekey from char[] = "MIICxjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9..."

Stokestack

Now I'm trying to replace the filepath with char[] which has all characters of the file.



I just did this today.  Do something like this, where privateKeyString is your unsigned char array with your PEM file contents in it:

            BIO* bp = BIO_new_mem_buf(privateKeyString, -1);    // Create a new memory buffer BIO.
            RSA* privKey = 0;
            if(bp)
            {
                privKey = PEM_read_bio_RSAPrivateKey(bp, 0, 0, 0);    // And read the RSA key from it.
                BIO_free(bp);
            }

            // Now check privKey to make sure it's not NULL!

NOTE: You need to make sure that privateKeyString includes the newline characters that occur in the file.  It won't work without them!

Hope that helps.

Gavin