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