42

I ran accross a CSR file (Certificate Signing Request) and I need to extract some information from it.

There's a way to decode it using .NET Framework?

Romias
  • 13,783
  • 7
  • 56
  • 85
  • 1
    There's an online tool at http://www.sslshopper.com/csr-decoder.html if you just want to look at it manually. – Rory Oct 01 '13 at 10:08

4 Answers4

49

It's not .NET, but for interactive use, try the OpenSSL utilities. Specifically:

openssl req -text -in request.csr
erickson
  • 265,237
  • 58
  • 395
  • 493
13
certutil -dump file.csr

Will also dump all relevant information. Builtin in Windows by default.

user11153
  • 8,536
  • 5
  • 47
  • 50
BZanten
  • 157
  • 1
  • 3
  • 2
    For the Windows environment, I believe this answer is best because it doesn't require installing OpenSSL or utilizing any external libraries. I spent quite a while searching for a native windows means of viewing the CSR contents, and here it is! – AdamantineWolverine Oct 20 '21 at 07:18
  • 1
    certutil is not builtin command in windows – Hus Mukh Jan 27 '22 at 17:11
6

Decoding a CSR is easy if you employ the OpenSSL.NET library:

// Load the CSR file
var csr = new X509Request(BIO.File("C:/temp/test.csr", "r"));
OR
var csr = new X509Request(@"-----BEGIN CERTIFICATE REQUEST-----...");

// Read CSR file properties
Console.WriteLine(csr.PublicKey.GetRSA().PublicKeyAsPEM);
Console.WriteLine(csr.Subject.SerialNumber);
Console.WriteLine(csr.Subject.Organization);
.
.
.

X509Request type has properties to get everything out of your CSR file text.

Ε Г И І И О
  • 11,199
  • 1
  • 48
  • 63
-1

Try Liping Dai's website. His LCLib has ASN1 Parser which wrote in C#. It can decode CSR. Work for me.

  • The website is gone now, some of it can be found at https://web.archive.org/web/20110817184958/http://lipingshare.com/Asn1Editor/. For ASN1 parsing, you could use `openssl asn1parse -in my.csr` – mwfearnley May 11 '23 at 09:36