3

I have a private key bytes stored in PEM format, in a variable of Type LPSTR. i.e

LPSTR pPrivateKeyInPem; 

Now I need to generate an EVP_PKEY using pPrivateKeyInPem, so that it can be loaded into an SSL_CTX Object using the SSL_CTX_use_PrivateKey() API of Openssl.

How can I do this?

Wtower
  • 18,848
  • 11
  • 103
  • 80
User1234
  • 1,543
  • 4
  • 22
  • 32
  • Welcome to Stack Overflow! I edited your question to properly format your code - please see the editing help for more information on formatting. I would also recommend you to use smaller sentences for readability. Please edit to add anything necessary to identify the specific problem. Good luck! – Wtower Dec 15 '15 at 08:01
  • Thanks @Wtower . I will keep this in mind :) – User1234 Dec 15 '15 at 09:12

1 Answers1

6

I'll omit conversion from LPSTR to char*, which is covered here: Convert lptstr to char*

For the OpenSSL part

BIO *mem;
mem = BIO_new_mem_buf(pkey, -1); //pkey is of type char*

key = PEM_read_bio_PrivateKey(mem, NULL, NULL, 0);
Leśny Rumcajs
  • 2,259
  • 2
  • 17
  • 33