我正在寻找从任何给定域名SSL证书的数据.例如,我想放在任何网址,例如“
https://stackoverflow.com”,我的代码首先检查是否存在SSL证书.如果是,那么我希望它能够提取证书的有效期. [我正在从DB读取Domainnames]
示例: http://www.digicert.com/help/
示例: http://www.digicert.com/help/
我需要创建一个Web服务来检查到期日.我该怎么实现呢? – 我已经查找了许多不同的东西,如RequestCertificateValidationCallback和ClientCertificates等.
我可能完全错了(为什么我需要帮助),但是我会创建一个HTTPWebRequest,然后以某种方式请求客户端证书和特定元素的方式?
我试过提供@ SSL certificate pre-fetch .NET的例子,但是我得到forbitten 403错误.
任何帮助将不胜感激 – 谢谢.
解决方法
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);
为了运行这个,你需要添加system.security来引用.