// Cert252.cpp // #include "stdafx.h" #include #include #include #define CERT_SUBJ_STR L"電子証明書の所有者名に変えてください" int _tmain(int argc, _TCHAR* argv[]) { HCRYPTPROV hProv; HCERTSTORE hStore; // CSPハンドルの取得 if(!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, NULL)) { if(!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) { fprintf(stderr, "CryptAcquireContext error\n"); return 1; } } // 証明書ストアーのオープン hStore = CertOpenSystemStore( hProv, "MY"); if(!hStore) { fprintf(stderr, "CertOpenSystemStore error\n"); return 2; } // 電子証明書の取り出し PCCERT_CONTEXT pcCert; pcCert = CryptUIDlgSelectCertificateFromStore( hStore, NULL, NULL, NULL, 0, 0, NULL); if(!pcCert) { CertCloseStore(hStore, 0); CryptReleaseContext(hProv, 0); return 1; } // 電子証明書詳細の表示 CryptUIDlgViewContext( CERT_STORE_CERTIFICATE_CONTEXT, // 電子証明書の詳細を表示 pcCert, // 表示する電子証明書 NULL, // 親ウインドウのハンドル NULL, // 表示されるウインドウのタイトル 0, NULL); // 後始末 CertFreeCertificateContext(pcCert); CertCloseStore(hStore, 0); CryptReleaseContext(hProv, 0); return 0; }