Reputation: 14049
How do I read X509v3 extension fields from a certificate? I iterated through AllKeys
in HttpClientCertificate
but that contains only the regular fields of the certificate & not the extension fields.
HttpClientCertificate cs = Request.ClientCertificate;
foreach (String s1 in cs.AllKeys)
Response.Write( s1 + ":" + cs[s1] + "<br>");
So how do I read the extension fields?
Upvotes: 0
Views: 1129
Reputation: 12978
Looking at the documentation of HttpClientCertificate and X509Certificate2, it looks like you should be able to get a byte array of the entire certificate in ASN.1 format by using the Certificate property of HttpClientCertificate
. Then use this byte array to instantiate an X509Certificate2
object through this constructor.
Once you have an X509Certificate2
object, you can get the extensions through the Extensions property. I'm not positive, but the extensions may also be listed when the toString() method is called on the X509Certificate2
object.
Upvotes: 1