Hi Dan,
Please try like:

 

char *key = "-----BEGIN RSA PRIVATE KEY----- \n"\
"jGK1T++C+Np4As+ KoaO2NCiCBN5UQJRzXBsZvLDoN6IcfxJwXklp560jrKiIZ8VU\n"\
  ..........................

  .........................

 

 "Drys2uVaAzmRhS6tGJ2fdwPnlSLJrQbHuP938BkyxNhdYN8drfqb\n"\
         "-----END RSA PRIVATE KEY-----\n";   

 

    BIO *bio = BIO_new_mem_buf(key, -1);



    SSL_CTX  *sslctx;
    EVP_PKEY *pktmp = NULL;

      If key don't have password protcted
    > pktmp = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);
    if your key having in PKCS12 format and password protected.  Please try
like This

    pktmp = PEM_read_bio_PrivateKey(bio,0,sslctx->default_passwd_callback,
sslctx->default_passwd_callback_userdata);


    if (pktmp == NULL) {
        char buffer[120];

        ERR_error_string(ERR_get_error(), buffer);
        fprintf(stderr, "OpenSSL error: %s", buffer);
    }    



 SSL_CTX_use_PrivateKey(sslctx,  pktmp);

 EVP_PKEY_free(pktmp);

Please try above. If you are again facing problem. Then please read key
using file pointer using fread(char *key will point private key) and please
compare to hardcode key pointer and key pointer from file.Beasause it is
working.

 

Thank you.

Regards,

--Ajeet  Kumar  Singh

 

 

  _____  

From: Dan Ribe [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 01, 2008 5:41 PM
To: Ajeet kumar.S
Subject: Re: Reading certificate and public key from memory

 

Hey,

How are u doing ?

Was trying to read my private key from the mem buffer like :

    char *key = "-----BEGIN RSA PRIVATE KEY-----"
    "jGK1T++C+Np4As+

KoaO2NCiCBN5UQJRzXBsZvLDoN6IcfxJwXklp560jrKiIZ8VU"
    "N2AZVq28yjqt3RYaRPn0xhbmLfWH/o+wzlg58wIDAQABAoIBAAHEep7qWWMFWsbc"
 
............................................................................
..
 
............................................................................
..                        

  "DwiD1OKnxTlAvZPkTSCS+QKBgDkXMM+2jyeRPwpUEyZjqYveVb5zc3HJMMGbpI/p"
    "09dirkd+sRoXWShF8ctVVb4B1PAFTOBEa8diickehnAyEq6KhzLWpQqhqCnylETw"
    "Drys2uVaAzmRhS6tGJ2fdwPnlSLJrQbHuP938BkyxNhdYN8drfqb"
    "-----END RSA PRIVATE KEY-----";    
    
    int keyLength = strlen(key);
    BIO *bio = BIO_new_mem_buf(key, keyLength);

    EVP_PKEY *pktmp = NULL;
    pktmp = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);

    if (pktmp == NULL) {
        char buffer[120];

        ERR_error_string(ERR_get_error(), buffer);
        fprintf(stderr, "OpenSSL error: %s", buffer);
    }    

But PEM_read_bio_PrivateKey() always returns an error like : 

OpenSSL error: error:0906D06C:PEM routines:PEM_read_bio:no start line

Any Help ?

Thanks much.

Cheers !

 

On Tue, Sep 30, 2008 at 2:33 PM, Ajeet kumar.S
<[EMAIL PROTECTED]> wrote:

Hi Dan,

I am solving this issue. I will get you back soon. It is not required to
change in other format.  You can use .PEM format.

 

Thank you.

Regards,

--Ajeet  Kumar  Singh

 

 

  _____  

From: Dan Ribe [mailto:[EMAIL PROTECTED] 
Sent: Monday, September 29, 2008 2:34 PM
To: [EMAIL PROTECTED]
Subject: Re: Reading certificate and public key from memory

 

Hi Ajeet,

Just wondering whether you was able to solve this one or not. Actually I
have similar problem in front of me. I want to read the private key directly
from the memory buffer. Currently I have the private key in form of a file
(.pem) on disk. I want to hard code its contents in my code & read them
directly from there. Doing so because I don't want to distribute the private
key with my product.

If you have already done this. Please share following information. 
1. How to hard code the value in some string buffer (how to convert the .pem
file to the required format).
2. How to read the key informaiton from the memory buffer. Please give me
some sample code, that will make my life much easiler.

Hoping for a prompt reply from your side. thanks much

Cheers !

On Mon, Sep 15, 2008 at 10:11 AM, Ajeet kumar.S
<[EMAIL PROTECTED]> wrote:

Dear All,

              In open ssl I saw we were passing file name of certificate and
public key. In openssl we used this name and reading certificates & keys
from that file. If instead of file name we want to pass char pointer which
point to address of certificate and public key respectively.

Is it possible? Actually I don't want to read certificates and keys from
file .I want to pass one memory pointer for each certificate and keys
respectively which stored both certificate and keys respectively.

Please tell me how to possible.

 

Thank you.

Regards,

--Ajeet  Kumar  Singh

 

 

 

 

 

<<image002.jpg>>

<<image003.jpg>>

Reply via email to