hope this fix your issue If you really need the PEM representation, then PEM_write_bio_RSA_PUBKEY() and PEM_write_bio_RSAPrivateKey() (along with their read counterparts) are the functions you want; give them memory BIOs to have them write into a memory buffer. You can create a memory BIO by invoking e.g.
BIO * b = BIO_new(BIO_s_mem());
void * buf;
BIO * b = BIO_new_mem_buf(buf, 9001)
Export openssl key to file
By : JuanJo Yanes
Date : March 29 2020, 07:55 AM
Hope this helps I generated a private key using commend: , You need to generate an crt file too.
// Generate the public key for the private key
$key = openssl_pkey_get_details($privateKey); // $privateKey is created with openssl_pkey_new()
// Save the public key in public.pem file