Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 系统存储区中的证书上下文始终具有无效的pbCertEncoded指针_C++_Windows_Ssl Certificate_Cryptoapi - Fatal编程技术网

C++ 系统存储区中的证书上下文始终具有无效的pbCertEncoded指针

C++ 系统存储区中的证书上下文始终具有无效的pbCertEncoded指针,c++,windows,ssl-certificate,cryptoapi,C++,Windows,Ssl Certificate,Cryptoapi,我试图在CryptoAPI中使用CertEnumCertificateSinstare来迭代所有根证书,并将它们编码到PEM文件中,以便与OpenSSL一起使用。我发现了一些这样的例子,因此这似乎是可能的,但是,我为每个证书返回的PCCERT_上下文有一个无效的指针,用于pbCertEncoded和cbCertEncoded缓冲区大小始终为0,但我觉得不应该是这种情况,因为示例使用编码缓冲区将证书转换为其他格式。是否有其他人遇到过获取空缓冲区的问题,或者可以看到我缺少的步骤 我已经通过Crypt

我试图在CryptoAPI中使用CertEnumCertificateSinstare来迭代所有根证书,并将它们编码到PEM文件中,以便与OpenSSL一起使用。我发现了一些这样的例子,因此这似乎是可能的,但是,我为每个证书返回的PCCERT_上下文有一个无效的指针,用于pbCertEncoded和cbCertEncoded缓冲区大小始终为0,但我觉得不应该是这种情况,因为示例使用编码缓冲区将证书转换为其他格式。是否有其他人遇到过获取空缓冲区的问题,或者可以看到我缺少的步骤

我已经通过CryptUIDlgViewContext函数验证了我实际上是在获取证书。我觉得我错过了一些非常基本的东西。基本代码如下:

HCERTSTORE hStore = CertOpenSystemStore(NULL, L"ROOT");

for ( PCCERT_CONTEXT pCertContext = CertEnumCertificatesInStore(hStore, NULL); pCertContext != NULL; pCertContext = CertEnumCertificatesInStore(hStore, pCertContext) )
    {

        // This shows the certificates fine
        CryptUIDlgViewContext(CERT_STORE_CERTIFICATE_CONTEXT,  pCertContext, NULL, NULL, 0, NULL)

        // but
        // pCertContext->pbCertEncoded is a Bad Ptr and
        // pCertContext->cbCertEncoded is always 0

        // If i try
        TCHAR *OutString = NULL;
        DWORD Size = 0;
        DWORD lastError;
        BOOL success = CryptBinaryToString(pCertContext->pbCertEncoded, pCertContext->cbCertEncoded, CRYPT_STRING_BASE64,OutString, &Size); 

        if( !success )
        {
            // I get a invalid parameter error here.
            lastError = GetLastError();
        }        
    }

以64位编译时,编码的缓冲区不会被填充。用32位编译似乎可以解决这个问题。

用64位编译时,编码的缓冲区不会被填满。用32位编译似乎可以解决这个问题。

我认为这只是CryptoApi的基本设置/使用,但你是对的。始终添加代码!而且,从长远来看,这基本上就是我要做的。我认为这只是CryptoApi的基本设置/使用,但你是对的。始终添加代码!而且,从长远来看,这基本上就是我要做的。