我的学校网页有自签名证书(需要手动安装)。我想创建一个程序,将certificate.cer
(来自Visual Studio资源)安装到本地用户的受信任的根证书颁发机构
中。
你知道我如何在C#中实现这个功能吗?
我的学校网页有自签名证书(需要手动安装)。我想创建一个程序,将certificate.cer
(来自Visual Studio资源)安装到本地用户的受信任的根证书颁发机构
中。
你知道我如何在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的一部分,可能无法自由分发。