var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var certificates = store.Certificates.Find(
X509FindType.FindByThumbprint, thumbprint, false);
X509Certificate2 cert = certificates[0];
现在我们有了 X509Certificate2 实例。如何查看是否可导出私钥? (最好不要尝试显式导出)
最佳答案
我在这里找到的另一种方法:How to determine whether an X509Certificate2 is exportable
X509Certificate2.PrivateKey Gets the AsymmetricAlgorithm object that represents the private key associated with a certificate.
The RSACryptoServiceProvider class is a AsymmetricAlgorithm
Then get the RSACryptoServiceProvider.CspKeyContainerInfo which is a CspKeyContainerInfo object that has a Exportable property that: Gets a value indicating whether a key can be exported from a key container.
更新:有效。因此,如果您使用 RSA 证书,这是可以接受的方法。
关于c# - 如何检查 X509Certificate2 是否可导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32354790/