I am curently using this function: PEM_read_bio_PUBKEY to read a public key. Is there any alternative function that instead of a PEM file you can read the key from a X509 crt file?
Asked
Active
Viewed 262 times
1 Answers
0
I found a solution by debuging the openssl cli util: I downloaded the openssl code and debuged it with the folowing args: x509 -in E:/mycert.crt -pubkey -out E:/mypubkey.pem
static EVP_PKEY *getPubKeyFromCRT(const char *filename) {
EVP_PKEY *pubkey = NULL;
X509_STORE *ctx_store = NULL;
X509 *x509_crt = NULL;
ctx_store = X509_STORE_new();
//TODO ERROR HANDLING
X509_STORE_set_verify_cb(ctx_store, callback_verify_cert);
if(!X509_STORE_set_default_paths(ctx_store)) {
//TODO ERROR HANDLING
}
x509_crt = getCertFromCRTFile(filename);
//TODO ERROR HANDLING
pubkey = X509_get_pubkey(x509_crt);
}

maxbit89
- 748
- 1
- 11
- 31
-
You should cite/attribute where you lifted the code. – jww Sep 15 '16 at 23:01