【问题标题】:Is there any way to get private key in EVP_KEY structure from windows certstore?有没有办法从 Windows certstore 获取 EVP_KEY 结构中的私钥?
【发布时间】:2017-04-15 23:57:50
【问题描述】:

我尝试使用 windows API(PFXExportCertStoreEx) 从 certstore 获取私钥。

此 API 能够从 certstore 导出 CRYPT_DATA_BLOB 以获取相应的 CERT_INDEX。但我需要 EVP_KEY 结构中的私钥,因为我的应用程序正在使用 openssl API 用于 SSL_CTX。所以导出的结构 CRYPT_DATA_BLOBit 不适合 SSL 上下文中的 EVP_PKEY(SSL_CTX)。

任何帮助将不胜感激。

我是这个 windows certstore 的新手。如果您需要更多信息,请告诉我。

【问题讨论】:

  • 您好!你明白了吗?我想要同样的东西!如果是这样,请与我们分享!

标签: windows openssl certificate private-key


【解决方案1】:
CRYPT_DATA_BLOB dataBlob = {0};
if(PFXExportCertStoreEx(hStore, &dataBlob, password, NULL,
            EXPORT_PRIVATE_KEYS | REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY | REPORT_NO_PRIVATE_KEY))
{
    if (dataBlob.cbData > 0)
    {
        dataBlob.pbData = (BYTE*)malloc(dataBlob.cbData);
        if (PFXExportCertStoreEx(hSystemStore, &dataBlob, password.toStdWString().c_str(), NULL,
                    EXPORT_PRIVATE_KEYS | REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY | REPORT_NO_PRIVATE_KEY))
        {
            EVP_PKEY *pkey;
            X509 *cert;
            STACK_OF(X509) *ca = NULL;
            PKCS12 *p12;
            int i;
            CRYPTO_malloc_init();
            OpenSSL_add_all_algorithms();
            SSLeay_add_all_algorithms();
            ERR_load_crypto_strings();

            BIO* input = BIO_new_mem_buf((void*)dataBlob.pbData, dataBlob.cbData);
            p12 = d2i_PKCS12_bio(input, NULL);

            PKCS12_parse(p12, password.toStdString().c_str(), &pkey, &cert, &ca);
        }
    }
}

【讨论】:

  • 在上面的代码中可能有用。它对我有用,但您需要使用 OpenSSL API @Carlos。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-04
  • 2020-10-24
  • 1970-01-01
  • 2012-12-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多