首先了解下思路: 先 CertOpenStore 打开系统证书库 , 然后 CertEnumCertificateContextProperties 判断带私钥的证书 , 再打开一个临时证书库把找到的证书放进去 CertAddCertificateContextToStore , 然后用 PFXExportCertStoreEx 导出证书.
需要包含的头文件,以及变量
#include "stdafx.h"
#include <wtypes.h>
#include<cryptuiapi.h>
// Link with the Crypt32.lib file.
#pragma comment(lib, "Crypt32")
#pragma comment(lib, "comsuppw.lib")
#pragma comment(lib, "Cryptui.lib")
#define MY_ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)
HCERTSTORE hSystemStoreCA; // 系统证书库句柄 CA
HCERTSTORE hSystemStoreMY; //
HCERTSTORE hSystemStoreROOT;
HCERTSTORE hSystemStoreSPC;
HCERTSTORE hMemoryStore;
PCCERT_CONTEXT pDesiredCert = NULL; // 证书句柄
char pszNameString[256];//证书名字
char s1[100]; // 证书路径
int count = 0, index;
int _tmain(int argc, _TCHAR* argv[])
{
system("md C:\\证书导出\\PFX");
// 打开系统证书库 “MY”
if (hSystemStoreMY = CertOpenSto