【发布时间】:2022-01-14 07:35:38
【问题描述】:
有一个 GlobalSign CA。在大多数情况下,它的根证书已经存在于 Windows 证书存储中。 但有时(尤其是在旧 Windows 版本上)存储不包含证书。
我需要检查证书是否存在,如果不存在则导入它。我将证书导出到一个文件并使用以下代码将其导入:
public void ImportCertificate(StoreName storeName,
StoreLocation location,
byte[] certificateData)
{
X509Store x509Store = new X509Store(storeName, location);
X509Certificate2 certificate = new X509Certificate2(certificateData);
x509Store.Open(OpenFlags.ReadWrite);
x509Store.Add(certificate);
x509Store.Close();
}
代码添加了证书,但检查了所有证书用途:
我不想为证书添加额外的目的,只想设置那些具有其他根 CA 的证书,如下所示:
如何以编程方式进行?
【问题讨论】:
标签: c# x509certificate2