惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
人人都是产品经理
人人都是产品经理
V
Visual Studio Blog
Last Week in AI
Last Week in AI
V
V2EX
博客园_首页
IT之家
IT之家
Jina AI
Jina AI
博客园 - 叶小钗
The Cloudflare Blog
T
Tailwind CSS Blog
腾讯CDC
B
Blog
D
Docker
L
LangChain Blog
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI

博客园 - 木头's

APACHE2.0 TOMCAT5.0 SSL 配置 smimedecryptvbs ASP.NET, Javascript tips: Encrypt /Sign /Verify signed message using Capicom ActiveX Using CAPICOM to obtain an SSL Certificate .NET and Certificate Stores net平台下的数字签名技术的讲解 java数字签名(签名生成,用证书验证签名) Apache安全应用资源文档 国外PKI/CA体系发展状况 CA基本常识:X.509标准 - 木头's - 博客园 PKI体系的十大风险 在职必看!受益无穷的28条职场语录 启用客户端证书并在 SharePoint Portal Server 2003 的内容搜索中使用客户端证书 一个基于RSA算法的Java数字签名例子 实现在 Linux 下 Tomcat 的双向SSL认证 JAVA对数字证书的常用操作 一组数据摘要算法的效率测试 一首歌曲,一种心情 职场必读
.Net读取数字证书信息和扩展域信息
木头's · 2011-01-19 · via 博客园 - 木头's

  最近涉及到项目中有采用.NET作为开发平台,因为之前对.NET的了解并不清楚,所以证书的部分信息读取可以,但在国家定义的扩展信息的内容时没有成功。最近重新看了微软的说明以及从网上找了部分信息,整理出来了读取证书扩展域信息的方法。

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Security.Cryptography.X509Certificates;

namespace Cert
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          
            X509Certificate cs = new X509Certificate(Request.ClientCertificate.Certificate);
            X509Certificate2 x509 = new X509Certificate2(cs);

          
            //税务扩展域信息读取开始
            X509Extension ext = x509.Extensions["1.2.86.11.7.5"];
            Byte[] byteArray = ext.RawData;
            String nsrsbh = System.Text.Encoding.ASCII.GetString(byteArray);
            nsrsbh = nsrsbh.Substring(3).Trim();//14位纳税人识别号
            //税务扩展域信息读取结束 
            String tempSubject="";//完整的用户DN
            String CN = "";//用户名称
            String SN = "";//数字证书序列号
            tempSubject = cs.Subject.ToString();
            int i = tempSubject.IndexOf("CN=");
            int k = tempSubject.IndexOf(',', i);
            if (k < 0)
            {    
                CN = tempSubject.Substring(i).Trim();
            }
            else
            {
                CN = tempSubject.Substring(i + 3, k).Trim();
            }
            SN = cs.GetSerialNumberString();//数字证书唯一序列号
            Response.Write("纳税人识别号 = " + nsrsbh + "<br>");
            Response.Write("用户名称 = " + CN + "<br>");
            Response.Write("数字证书唯一序列号 = " + SN + "<br>");
            Response.Write("证书称 = " + tempSubject + "<br>");

        }
    }
}