Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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# x509certificate2中的私钥为空_C#_Ssl_Private Key_X509certificate2 - Fatal编程技术网

C# x509certificate2中的私钥为空

C# x509certificate2中的私钥为空,c#,ssl,private-key,x509certificate2,C#,Ssl,Private Key,X509certificate2,我已使用私钥在本地计算机存储(win7)上安装了证书。 在c代码中,我这样做: X509Certificate2 cert = null; var store = new X509Store(storeName, storeLocation); store.Open(OpenFlags.ReadOnly); try { var result = store.Certificates.Find(

我已使用私钥在本地计算机存储(win7)上安装了证书。 在c代码中,我这样做:

        X509Certificate2 cert = null;
        var store = new X509Store(storeName, storeLocation);
        store.Open(OpenFlags.ReadOnly);
        try
        {
            var result = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
            cert = result.Count > 0 
                ? result[0] 
                : null;
        }
        finally
        {
            store.Close();
        }
        return cert;
cert变量中,我有我的证书,但它有问题:HasPrivateKey为true,但PrivateKey没有任何对象。如果我在web应用程序的C#代码中与REST请求一起发送,则会出现错误:

AcquireCredentialsHandle() failed with error 0X8009030D.
The request was aborted: Could not create SSL/TLS secure channel.
对存储中的证书授予所有权限。请帮忙,怎么了

Certutil结果为俄语(我用“***”隐藏安全信息):


我已经解决了问题。我从机器存储中删除了证书,然后将已安装的证书从当前用户存储导出到.pfx文件,并将其导入机器存储中。现在PrivateKey有了对象。 在下一步中,我将协议类型从Tls更改为Tls12(适用于Win7+):


您能否显示以下命令的结果:
certutil-storemythumbprint
。用实际值替换
指纹
。我怀疑密钥使用CNG提供程序。在第一篇文章中添加了certutil结果。证书看起来正常。实际错误是“无法识别提供给包的凭据”。也许这对你有意义?谁是最权威的人?最可能的情况是通信的另一方不信任它。至于PrivateKey为null,通常不会从存储中提取此信息。毕竟,你不想将你的私钥发送给另一方。谢谢你的提示。我在这里找到了答案:。我从机器存储中删除了证书,然后将已安装的证书从当前用户存储导出到.pfx文件,并将其导入机器存储中。现在PrivateKey有了对象,但我仍然无法接收来自服务器的响应-请求因超时而中止。但我在Chrome浏览器和Postman中收到了服务器的正确响应。有什么想法吗?
certutil -store my "cf 35 63 34 14 30 a0 32 ca 4a 58 b9 7a 7a ab 18 a4 47 7d a4"
================ Сертификат 0 ================
Серийный номер: 100030
Поставщик: ******************************
 NotBefore: 07.07.2015 5:00
 NotAfter: 24.12.2023 4:59
Субъект: ********************************
Не корневой сертификат
Шаблон:
Хеш сертификата(sha1): cf 35 63 34 14 30 a0 32 ca 4a 58 b9 7a 7a ab 18 a4 47 7d a4
  Контейнер ключа = 94c3b04b44d51674a1b7de89c10bd7d7_09614f03-cc81-44e6-a978-81773242876c
  Простое имя контейнера: CertReq-ceda22d5-2893-496a-b8c1-5c9ceaed82f1
  Поставщик = Microsoft Strong Cryptographic Provider
Тест шифрования пройден
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;