Question

How to get private key with asn format from pfx? I need to get the private key with asn format to put to Qt's variable QSslKey to connect https server.

I have to use Win32 Api to do it, and I can't use OpenSSL to transform it.

First I try to get the private key directly:

1.CertOpenSystemStore(NULL, _T("MY"))
2.CryptAcquireCertificatePrivateKey(...)
3.CryptGetUserKey(...)
4.CryptExportKey(...)

But the private key I have got, I don't know how to use it.

Was it helpful?

Solution

Warning : This is not the exact answer for your question, but i hope it will give you some help towards what you want to acheive

Based on my experience, Windows crypto APIs are designed to use the private key within the certificate store rather than export the key outside, unless you are using CryptoAPI standard functions like PFXExportCertStoreEx ().

CryptExportKey function gives the private/public key pair in a key blob structure which you have to convert to the format you want. The closest thing i have ever seen this being being done is in

Openssl engine for Windows, filename : e_capi.c

refer to the function

 **capi_load_privkey() and subfunction capi_get_pkey()**

Here conversion of the Key blob to OpenSSL compatible structure is done. Hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top