如果我已經正確理解了你,下面的代碼片段顯示瞭如何從證書中提取關鍵提供者信息。
void trace(char* message, DWORD errorCode)
{
cout << message << errorCode;
}
std::wstring Test_CertGetCertificateContextProperty(PCCERT_CONTEXT pCertContext)
{
DWORD dwSize = 0;
BOOL bIsSuccess = CertGetCertificateContextProperty(pCertContext,
CERT_KEY_PROV_INFO_PROP_ID,
NULL,
&dwSize);
if (!bIsSuccess)
{
trace("CertGetCertificateContextProperty failed with error: ", GetLastError());
return L"";
}
PCRYPT_KEY_PROV_INFO pKeyProvInfo = (PCRYPT_KEY_PROV_INFO)LocalAlloc(LMEM_ZEROINIT, dwSize);
if (pKeyProvInfo == NULL)
{
trace("LocalAlloc failed with error:", GetLastError());
return L"";
}
bIsSuccess = CertGetCertificateContextProperty(pCertContext,
CERT_KEY_PROV_INFO_PROP_ID,
pKeyProvInfo,
&dwSize);
std::wstring provName;
if (bIsSuccess)
{
provName = pKeyProvInfo->pwszProvName;
}
LocalFree(pKeyProvInfo);
return provName;
}
來源
2011-10-17 13:28:55
Raj