I have a DER certificate from which I am retrieving the Public key in unsigned char buffer as following, is it the right way of getting?
pStoredPublicKey =
Convert EVP_PKEY to character buffer.
char *EVP_PKEY_to_PEM (EVP_PKEY *pkey)
{
BIO *bio = NULL;
char *pem = NULL;
if (NULL == pkey)
return NULL;
if ((bio = BIO_new(BIO_s_mem())) == NULL)
return NULL;
if (0 == PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL)){
BIO_free(bio);
return NULL;
}
pem = (char *) calloc(1, bio->num_write + 1);
BIO_read(bio, pem, bio->num_write);
BIO_free(bio);
return pem;
}