title: Bouncy Castle Decode CSR c#
body: <p>I'm attempting to learn how to decode a csr with the bouncy castle as I intend to use it to learn other crypto things. </p>
  
  <p>I'm also not finding any documentation for c# just java. </p>
  
  <p>Here's how I'm calling <code>DecodeCSR(string str)</code>:</p>
  
  <pre><code> static void Main(string[] args)
      {
          string csr = "-----BEGIN NEW CERTIFICATE REQUEST-----...";
          DecodeCSR(csr);
          Console.ReadLine();
      }
  </code></pre>
  
  <p>Here's my method where I'm getting an IO Exception(Included below), my main problem is I don't know what to give <code>Pkcs10CertificationRequest</code>.</p>
  
  <pre><code>private static void DecodeCSR(string csr)
      {
          try
          {
              byte[] csrEncode = Encoding.UTF8.GetBytes(csr);
              Pkcs10CertificationRequest csrDecoder = new Pkcs10CertificationRequest(csrEncode);
              byte[] csrDecode = csrDecoder.GetEncoded();
          }
          catch (IOException e)
          {
              Console.WriteLine(e);
          }
  
      }
  </code></pre>
  
  <p>The error message:</p>
  
  <pre><code> System.IO.IOException: unknown tag 13 encountered
     at Org.BouncyCastle.Asn1.Asn1InputStream.BuildObject(Int32 tag, Int32 tagNo, Int32 length)
     at Org.BouncyCastle.Asn1.Asn1InputStream.ReadObject()
     at Org.BouncyCastle.Asn1.Asn1Object.FromByteArray(Byte[] data)
     at Org.BouncyCastle.Pkcs.Pkcs10CertificationRequest..ctor(Byte[] encoded)
  </code></pre>