I am trying to extract the publickey from a certificate using OpenSSL in C and then convert it to .der format, but I cannot manage to do it.
The goal is to extract to extract to public key to implement pinning, like here: https://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html (public key extraction)
I am using the code from this tutorial.
BIO *certbio = NULL;
X509 *cert = NULL;
ret = BIO_read_filename(certbio, cert_path);
cert = PEM_read_bio_X509(certbio, NULL, 0, NULL));
EVP_PKEY *pkey = X509_get_pubkey(cert));
How can I convert from EVP_PKEY* to an unsigned char* in .der format? Or perhaps get it in .pem format and then convert it? Thanks