. Net reads Digital Certificate Information and extended domain information

Source: Internet
Author: User

Recently used in related projects. net as the development platform, because. net is not clear, so some information about the certificate can be read, but the content of the country-defined extended information is not successful. I recently reviewed Microsoft's instructions and found some information from the Internet, and sorted out how to read the certificate extended domain information.

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 );


// Start to read the tax extension Domain Information
X509extension ext = x509.extensions ["1.2.86.11.7.5"];
Byte [] bytearray = ext. rawdata;
String nssbh = system. Text. encoding. ASCII. getstring (bytearray );
Nssbh = nssbh. substring (3). Trim (); // 14-digit taxpayer identification number
// The reading of the tax extension domain information is complete.
String tempsubject = ""; // complete user DN
String Cn = ""; // User Name
String Sn = ""; // digital certificate serial number
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 (); // unique serial number of the digital certificate
Response. Write ("taxpayer identification number =" + nssbh + "<br> ");
Response. Write ("user name =" + CN + "<br> ");
Response. Write ("Digital Certificate unique serial number =" + Sn + "<br> ");
Response. Write ("Certificate Name =" + tempsubject + "<br> ");

 

 

}
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.