c# - 如何检查 X509Certificate2 是否可导出

标签 c# .net certificate

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/

相关文章:

c# - GroupBy 元组列表 C#

web.config 中的 C# Formsauthentication 超时是否会否决手动票证超时?

.net - 需要创建一个也保存类型的动态 ConfigurationSection

.net - 将 Perfmon 分析解释为特定于应用程序的观察/数据的最佳方法是什么?

push-notification - Apple Watch 的推送通知

azure - 如何使用 IdentityServer4 的 Azure 证书

c# - IDependencyResolver 是一种反模式吗?

C# :How can i set Memory stream as the asp. 网络图像控件的源属性?

.net - ElasticSearch .Net Nest问题与配置indexSettings

java - 在 Java cacerts 中导入根证书和中间证书的正确方法