问题描述
我想从Windows存储中获取私钥并将其转换为PEM,以便在OpenSSL中使用它.我一直在寻找一种可以做到这一点的方法!
I want to get a private key from windows store and convert it to PEM in order to use it in OpenSSL.I've been looking for a way to do that for a few hours!
- 我使用CertFindCertificateInStore()获取CERT_CONTEXT(我知道它包含使用搜索参数的私钥).
- 接下来,我使用CryptAcquireCertificatePrivateKey()来获取HCRYPTPROV(只是由于函数的名称).
- 现在,我使用CryptGetUserKey()获取HCRYPTKEY(只是因为听起来不错...?!)
但是现在我又被卡住了.
But now I'm stuck again.
我认为这是Microsoft所做的默默无闻的安全措施,以确保我们永远无法获得私钥.
I think this is security by obscurity done by Microsoft to make sure we will never be able to get private keys.
推荐答案
前两个很好.但是您需要使用 CryptExportPKCS8 .它将以PKCS#8 DER编码的形式将私钥导出到缓冲区.在PKCS#8中,您可以将其放入OpenSSL的X509结构中(通过使用d2i函数和内存缓冲区作为BIO结构中的输入).
First two are fine. But you need to use CryptExportPKCS8. It will export the private key to a buffer in PKCS #8 DER encoded form. From PKCS #8, you can get it into X509 structure of OpenSSL (by using d2i functions and memory buffer as input in BIO structures).
但是,如果私钥被标记为不可导出,则此功能将失败.
However, if the private key is marked as non-exportable, this function will fail.
您只能使用这种私钥对数据进行签名.
Only use you can do is to sign the data using such private key.
这篇关于将Windows存储区中的私钥转换为PEM(对于OpenSSL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!