获得.NET SSL证书 [英] get ssl certificate in .net
问题描述
我期待从任何给定的域名的SSL证书获取数据。例如,我希望把任何网站地址例如 http://stackoverflow.com 和我的code会首先检查是否SSL证书存在。如果是的话那么我想它拉出证书的失效日期。 [我从DB读DOMAINNAMES]
例如: http://www.digicert.com/help/
我需要创建一个Web服务来检查失效日期。我怎么才能实现它? - 我已经看过了不同的东西,如RequestCertificateValidationCallback和ClientCertificates等
负荷。我可能是完全错误的(所以为什么我需要帮助),但我想创建一个HttpWebRequest和然后以某种方式要求客户端证书和具体内容呀?
我试过的例子提供@ SSL证书pre取.NET ,但我正在逐渐forbitten 403错误。
任何帮助将是非常美联社preciated - 谢谢
使用System.Security;
使用System.Security.Cryptography;
使用System.Security.Cryptography.X509Certificates; //做的WebRequest获取有关安全网站信息
HttpWebRequest的要求=(HttpWebRequest的)WebRequest.Create(https://mail.google.com);
HttpWebResponse响应=(HttpWebResponse)request.GetResponse();
response.Close(); //获取SSL证书并将其分配给一个X509Certificate对象
x509证书证书= request.ServicePoint.Certificate; //通过传递到它的构造转换为X509Certificate到X509Certificate2对象
X509Certificate2 cert2 =新X509Certificate2(CERT); 串CN = cert2.GetIssuerName();
字符串cedate = cert2.GetExpirationDateString();
字符串cpub = cert2.GetPublicKeyString(); //显示证书对话框
X509Certificate2UI.DisplayCertificate(cert2);
为了运行这个,你需要添加system.security参考。
i am looking to get the data from any given domain names SSL certificate. For example I want to put in any website address e.g. "http://stackoverflow.com" and my code would firstly check if an SSL certificate exists. If it does then I want it to pull out the expiry date of the certificate. [ i am reading Domainnames from DB ] Example :http://www.digicert.com/help/
i need to create a web service to check expiry date. how can i implement it?? - I have looked up loads of different things such as RequestCertificateValidationCallback and ClientCertificates etc.
I could be completely wrong (hence why I need help) but would I create a HTTPWebRequest and then somehow request the client certificate and specific elements that way?
i tried the example provided @SSL certificate pre-fetch .NET , but i am getting forbitten 403 error.
Any help would be much appreciated - Thank you.
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://mail.google.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);
string cn = cert2.GetIssuerName();
string cedate = cert2.GetExpirationDateString();
string cpub = cert2.GetPublicKeyString();
//display the cert dialog box
X509Certificate2UI.DisplayCertificate(cert2);
in order to run this you need to add system.security to reference.
这篇关于获得.NET SSL证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!