User1234
User1234

Reputation: 1643

Generate EVP_PKEY from Private Key Bytes In PEM Format

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?

Upvotes: 3

Views: 3682

Answers (1)

Leśny Rumcajs
Leśny Rumcajs

Reputation: 2526

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);

Upvotes: 7

Related Questions