I have this code:
int importKey(){
FILE *fp=NULL;
RSA *pkey=NULL;
R_RSA_PRIVATE_KEY prk; //special structure
fp = fopen("sslcert/key.pem", "r");
fseek(fp, 0, SEEK_SET);
PEM_read_RSAPrivateKey(fp, &pkey, NULL, NULL);
if (!pkey)
{
fseek(fp, 0, SEEK_SET);
d2i_RSAPrivateKey_fp(fp, &pkey);
}
prk.bits=BN_num_bits(pkey->n);
return pkey; //check if pkey==0 or something else
}
This works just fine when I give .pem
file to fp what I created from command line using openssl -pkcs12 -in file.pfx -out key.pem
. But what I need is to use that pfx file in fp = fopen()
and somehow "extract" private key inside code and save it into that RSA *pkey and also extract certificate from the same pfx file and save it into X509 *px509 variable. Any help with that?
Meaning I need in fact some openssl functions to do the some routine as that command line command