![](/img/trans.png)
[英]BouncyCastle PrivateKey To X509Certificate2 PrivateKey
[英]Empty PrivateKey in x509certificate2
我已使用私鑰在本地計算機商店(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是真的但是PrivateKey沒有任何對象。 如果我使用我的Web應用程序的C#代碼中的REST請求發送它我有錯誤:
AcquireCredentialsHandle() failed with error 0X8009030D.
The request was aborted: Could not create SSL/TLS secure channel.
商店中的證書授予所有權利。 請幫幫忙,有什么不對?
Certutil導致俄語(我用“***”隱藏安全信息):
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
Тест шифрования пройден
我發現了這個問題。 我從機器商店刪除了證書,然后將安裝的證書從當前用戶商店導出到.pfx文件,並將其導入機器商店。 現在PrivateKey有了對象。 更多的步驟,我將協議類型從Tls更改為Tls12(適用於Win7 +):
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.