使用Crypto API解析私钥文件 [英] parse private key file with Crypto API
问题描述
大家好,
我正在使用Visual C ++ 6在我的应用程序中使用Crypto API.我得到了一个密钥对(打包在pfx文件中,已被选为cer文件作为公钥文件,而prk文件则作为prk文件被挑选出来). openssl framework),在其中我可以将cer文件解析为
具有CertCreateCertificateContext函数的公共密钥结构CERT_PUBLIC_KEY_INFO,但是我无法解析私有密钥结构. MS Crypto API是否支持此功能?
谢谢您的时间.
I'm using Crypto API in my application with Visual C++ 6. I got a keypair (packed in a pfx file, has been picked out the public key file as a cer file and the private key file as a prk file with openssl framework ), in which I can parse the cer file into
the public key structure CERT_PUBLIC_KEY_INFO with CertCreateCertificateContext function, but I can't parse the private key structure. Does MS Crypto API support this?
Thank you for your time.
此致,
月雯.
Regards,
Yuewen.
推荐答案
您可以从PFX/PKCS#12文件中提取私钥,并使用Crypto API解析其内容.您将不得不使用该功能 带有标志 CRYPT_EXPORTABLE 的PFXImportCertStore .然后,您应该使用枚举返回的商店中的所有证书 CertEnumCertificatesInStore .在返回的证书中,选择具有该属性的证书 设置了CERT_KEY_PROV_INFO_PROP_ID .从那里,您可以使用经典 CryptAcquireContext , CryptGetUserKey 和 CryptExportKey 以便检索私钥blob.
You can extract the private key from a PFX/PKCS#12 file and parse its content using Crypto API. You will have to use the function PFXImportCertStore with the flag CRYPT_EXPORTABLE . Then you should enumerate all certificate in the returned store using CertEnumCertificatesInStore . Among the returned certificates, pick the one that has the property CERT_KEY_PROV_INFO_PROP_ID set. From there, you can use the classical CryptAcquireContext , CryptGetUserKey and CryptExportKey in order to retrieve the private key blob.
我编写了一个小工具,可以执行完全相同的操作,并且可以在控制台上打印私钥组件.您可以从以下链接获取其来源:
http://www.idrix.fr/Root/Samples/pfx_parse.cpp
I have written a small utility that do exactly the same thing and it prints the private key components on the console. You can get its source from the following link :
http://www.idrix.fr/Root/Samples/pfx_parse.cpp
我希望这会有所帮助.
干杯,
-
Mounir IDRASSI
IDRIX
http://www.idrix.fr
Cheers,
--
Mounir IDRASSI
IDRIX
http://www.idrix.fr
这篇关于使用Crypto API解析私钥文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!