2011-11-08 18 views
2

アンマネージドを使用して、以下のC#コードと同等の処理を行う方法を知っている人はいませんか? C++すなわちX509証明書ストアの証明書を拇印で照会しますか?アンマネージドC++を使用したX509証明書ストアへのアクセス

 var store = new X509Store(StoreName.My, StoreLocation.LocalMachine); 

     store.Open(OpenFlags.ReadOnly); 

     var allCerts = store.Certificates; 

     foreach (var certificate in from X509Certificate2 certificate in allCerts 
            where certificate.Thumbprint != null 
             && certificate.Thumbprint.Equals(thumbprint, StringComparison.OrdinalIgnoreCase) 
            select certificate) 
     { 
      return certificate; 
     } 

あなたが望むものを達成するためには事前のおかげで

デイブ

答えて

4

は、あなたは、Win32 CryptAPIライブラリに見てする必要があります。それは.NETほど簡単ではありません。 CertOpenStoreCertFindCertificateInStoreを参照してください。

証明書ストアを開いてCertFindCertificateStoreに渡し、証明書を検索するために使用する基準を保持する構造を作成する必要があります。あなたは

HCERTSTORE hSysStore = NULL; 
    PCCERT_CONTEXT pDesiredCert = NULL; 
if(hSysStore = CertOpenStore(
    CERT_STORE_PROV_SYSTEM,   // The store provider type 
    0,        // The encoding type is 
            // not needed 
    NULL,       // Use the default HCRYPTPROV 
    CERT_SYSTEM_STORE_CURRENT_USER, // Set the store location in a 
            // registry location 
    L"MY"       // The store name as a Unicode 
            // string 
    )) 
{ 
    //We have our store, let's do stuff with it 
    if (pDesiredCert = CertFindCertificateInStore(.....) { ..... } 
} 
else 
{ 
    //Error stuff 
} 

はあなたが#include <Wincrypt.h>#include <windows.h>

にする必要があります

シリアル番号、署名などを使用することができます
関連する問題