从Web浏览器控件打开证书信息 [英] Open Certificate Information from Web Browser Control

查看:804
本文介绍了从Web浏览器控件打开证书信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何基于来自 web浏览器控制SSL来打开证书​​信息屏幕?

Does anyone know how to open up the "Certificate Information" screen based on the SSL from the WebBrowser control?

推荐答案

这可以通过使用一类叫做 X509Certificate2UI 实现的。

This can be achieved by using a class called X509Certificate2UI.

为使这个类avalable给你,你需要添加一个引用 System.Security.dll

To make this class avalable to you, you need to add a reference to System.Security.dll

X509Certificate2UI 类有一个名为meyhod DisplayCertificate()这需要一个 X509Certificate2 对象作为参数。当被调用时,此方法显示一个对话框,显示所有的证书信息,包括链接,完全一样的对话框,你会发现在IE浏览器。

In the X509Certificate2UI class you have a meyhod called DisplayCertificate() which takes an X509Certificate2 object as a parameter. When invoked, this method shows a dialog box displaying all cert information including chaining, exactly the same as the dialog box you will find in IE.

WebBrowser控件只能返回一个 X509证书然后可以传递到 X509Certificate2的构造类。

The webbrowser control can only return a X509Certificate which can then be passed into the constructor of the X509Certificate2 class.

所以,code看起来这样的:

So the code looks as such:

//includes on top
using System.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

//Do webrequest to get info on secure site
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://securesite.com");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close();

//retrieve the ssl cert and assign it to an X509Certificate object
X509Certificate cert = request.ServicePoint.Certificate;

//convert the X509Certificate to an X509Certificate2 object by passing it into the constructor
X509Certificate2 cert2 = new X509Certificate2(cert);

//display the cert dialog box
X509Certificate2UI.DisplayCertificate(cert2);

这篇关于从Web浏览器控件打开证书信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆