[英]How can I install a certificate into the local machine store programmatically using c#?
[英]How to programmatically install a certificate using C#
我的学校网页有自信任证书(你必须手动安装),我想创建一个程序,在我点击一个按钮后,将证书.cer(来自 Visual Studio 资源)安装到本地用户 -“受信任的根证书颁发机构”。知道如何在 Visual C# 中编码吗?
要以编程方式将证书添加到当前用户的受信任根存储区,请使用X509Store和X509Certificate2类。 例如:
string file; // Contains name of certificate file
X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadWrite);
store.Add(new X509Certificate2(X509Certificate2.CreateFromCertFile(file)));
store.Close();
另请参阅“ 如何使用 c# 以编程方式将证书安装到本地机器存储中? ”。
另一个选项是证书管理器命令行 (certmgr.exe)工具,特别是:
certmgr /add cert.cer /s Root
其中“cert.cer”是您的证书。 这会将其导入到当前用户的受信任根存储中。 但是,certmgr.exe 是 Visual Studio 和 Windows SDK 的一部分,可能无法自由分发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.