To load a private key directly from disk, use the PEM_read_PrivateKey
function:
FILE *f;
EVP_PKEY *pkey;
f = fopen("key.pem", "rb");
PEM_read_PrivateKey(
f, /* use the FILE* that was opened */
&pkey, /* pointer to EVP_PKEY structure */
NULL, /* password callback - can be NULL */
NULL /* parameter passed to callback or password if callback is NULL */
);
To load a private key from a BIO
, use PEM_read_bio_PrivateKey
:
BIO *bio;
bio = BIO_new_mem_buf((void *)input, input_len);
PEM_read_bio_PrivateKey(
bio, /* BIO to read the private key from */
&pkey, /* pointer to EVP_PKEY structure */
NULL, /* password callback - can be NULL */
NULL /* parameter passed to callback or password if callback is NULL */
);