如何以编程方式安装证书使用C#

编程入门 行业动态 更新时间:2024-10-28 21:28:57
本文介绍了如何以编程方式安装证书使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的学校网页有selftrusted证书(你必须手动安装),我想要创建程序,将安装一个certificate.cer(从visual studio资源)到本地用户 - 受信任的根证书颁发机构,我点击一个按钮。

my school webpages have selftrusted certificate(you must install it manually) and I wanted create program that will install a certificate.cer (from visual studio resources) to Local user -"Trusted root certificate authority" after i click on a button.Do you know how to code it in Visual C#?

推荐答案

将证书添加到当前用户的受信任根存储以编程方式使用 X509Store 和 X509Certificate2 类。例如:

To add the certificate to the trusted root store for the current user programmatically, use the X509Store and X509Certificate2 classes. For example:

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#以编程方式将证书安装到本地机器存储?

See also " How can I install a certificate into the local machine store programmatically using c#? ".

另一个选项是证书管理器命令行(certmgr.exe)工具,具体为:

Another option is the Certificate Manager command line (certmgr.exe) tool, specifically:

certmgr /add cert.cer /s Root

其中cert.cer是您的证书。这将它导入到当前用户的受信任的根存储。但是,certmgr.exe是Visual Studio和Windows SDK的一部分,可能无法自由分发。

where "cert.cer" is your certificate. This imports it into the trusted root store for the current user. However, certmgr.exe is part of Visual Studio and the Windows SDK and may not be freely distributable.

更多推荐

如何以编程方式安装证书使用C#

本文发布于:2023-05-25 10:50:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/226551.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:证书   方式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!