C#确定X509Certificate2私钥是否可导出(redux)

时间:2018-02-18 17:05:24

标签: c# windows certificate x509certificate x509certificate2

我有时间决定X509Certificate2证书的私钥是否可导出。根据我所做的研究,我应该使用 CspKeyContainerInfo 。这是我到目前为止(为简洁起见,删除错误检查)。假设RSA证书指纹 存在且 拥有私钥。

X509Certificate2 cert = Cryptography.GetCertificateFromStore(thumbprint);
RSACryptoServiceProvider provider = (RSACryptoServiceProvider)cert.PublicKey.Key;
Debug.WriteLine("RSA Certificate Gettting Exportable status");
// next line generates exception "Key does not exist"
bool isexportable = provider.CspKeyContainerInfo.Exportable;
Debug.WriteLine("RSA Certificate Exportable="+isexportable.ToString());

0 个答案:

没有答案