Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# x509 certificate decoder

I'm looking for a C# code how to decode x509 certificate from string like in this page: https://www.sslshopper.com/certificate-decoder.html

I have a certificate string, that starts with MII... and ends with == .

When I past it in https://www.sslshopper.com/certificate-decoder.html it works but I want to have my own tool like this site.

Any help?

like image 899
zchpit Avatar asked Oct 10 '16 08:10

zchpit


1 Answers

I have a certificate string, that starts with MII... and ends with ==

it is a Base64 formatting of the ASN.1 DER encoded certificate. You can convert this string to a byte array and then construct an instance of X509Certificate2 class:

byte[] bytes = Convert.FromBase64String("MII<...>==");
var cert = new X509Certificate2(bytes);

For further reading:

Convert.FromBase64String Method (String)

X509Certificate2 Class

like image 167
Crypt32 Avatar answered Oct 20 '22 11:10

Crypt32