This is how I read a RSA key from a string buffer
where private_key is char * terminated by a \0

RSA *pub_key=NULL;
BIO *mem_ptr=NULL;
EVP_PKEY *pkey = NULL;
        
mem_ptr = BIO_new(BIO_s_mem());
BIO_puts(mem_ptr, private_key);
pkey = PEM_read_bio_PrivateKey(mem_ptr, 0, 0, 0);
pub_key = EVP_PKEY_get1_RSA(pkey);

Hope this helps

- Sid

--- Niklas Olsson <[EMAIL PROTECTED]> wrote:

> 
> Hi,
> I have been look through this mailing list to try to
> understand how to read 
> the public key and encrypt my message.
> 
> so far I think I should use
> 
> PEM_read_bio_RSAPublicKey
> and
> RSA_public_encrypt
> 
> I get the certificate in a buffer from the server
> (TLS - ServerHello 
> message)
> 
> I would think I should use
> BIO *in=NULL;
> in = BIO_new_mem_buf(cert, 1558); //cert if the
> buffer with the certifiate
> RSA *pKey=NULL;
> pKey = PEM_read_bio_RSAPublicKey(in,NULL, NULL,
> NULL);
> 
> but pKey is always NULL, I thought maybe the in
> buffer should only be the 
> public key so I copied that only, but again I only
> get a pKey that is NULL.
> 
> How am I supposed to read my certificate and get a
> correct RSA *pKey?
> 
> thanks!
> 
>
_________________________________________________________________
> Chat: Ha en fest på Habbo Hotel 
> http://habbohotel.msn.se/habbo/sv/channelizer Checka
> in här!
> 
>
______________________________________________________________________
> OpenSSL Project                                
> http://www.openssl.org
> User Support Mailing List                   
> [EMAIL PROTECTED]
> Automated List Manager                          
> [EMAIL PROTECTED]
> 



                
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to