Access X509 Certificate store with unmanaged C++

后端 未结 2 1457
暖寄归人
暖寄归人 2021-01-22 14:01

Does anyone know how I would do the equivalent of the below C# code using unmanaged C++ i.e. query a certificate from the X509 certificate store by thumbprint?

2条回答
  •  感动是毒
    2021-01-22 14:43

    The code from CertFindCertificateInStore. will not work on newer systems. On newer versions of Windows the certificate's name or subject are in Unicode format which uses 2 bytes for each character. The folowing line:

    LPCSTR lpszCertSubject = (LPCSTR) "Cert_subject_1";
    

    has to be change into:

    LPCWSTR lpszCertSubject = (LPCWSTR ) L"Cert_subject_1";
    

    or

    LPCTSTR lpszCertSubject = (LPCTSTR ) _T"Cert_subject_1"; // add #include  
    

    depending on what you need.

提交回复
热议问题