加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 在.net中获取ssl证书

发布时间:2020-12-15 18:13:52 所属栏目:百科 来源:网络整理
导读:我正在寻找从任何给定域名SSL证书的数据.例如,我想放在任何网址,例如“ https://stackoverflow.com”,我的代码首先检查是否存在SSL证书.如果是,那么我希望它能够提取证书的有效期. [我正在从DB读取Domainnames] 示例: http://www.digicert.com/help/ 我需要
我正在寻找从任何给定域名SSL证书的数据.例如,我想放在任何网址,例如“ https://stackoverflow.com”,我的代码首先检查是否存在SSL证书.如果是,那么我希望它能够提取证书的有效期. [我正在从DB读取Domainnames]
示例: 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来引用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读