.netdigital-certificatecsr

How to decode a CSR File?


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?


Solution

  • 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.