title: C# How can I validate a Root-CA-Cert certificate (x509) chain?
body: <p>Let's say I have three certificates (in Base64 format)</p>
  
  <pre><code>Root
   |
   --- CA
       |
       --- Cert (client/signing/whatever)
  </code></pre>
  
  <p>How can I validate the certs and certificate path/chain in C#?
  (All those three certs may not be in my computer cert store)  </p>
  
  <p><strong>Edit</strong>: BouncyCastle has the function to verify. But I'm trying not to use any third-party library.</p>
  
  <pre><code>    byte[] b1 = Convert.FromBase64String(x509Str1);
      byte[] b2 = Convert.FromBase64String(x509Str2);
      X509Certificate cer1 = 
          new X509CertificateParser().ReadCertificate(b1);
      X509Certificate cer2 =
          new X509CertificateParser().ReadCertificate(b2);
      cer1.Verify(cer2.GetPublicKey());
  </code></pre>
  
  <p>If the cer1 is not signed by cert2 (CA or root), there will be exception. This is exactly what I want.</p>