title: How to read Pkcs#7 certificate chain from file/stream in C#?
body: <p>I have two certificates that I saved to disk. One is a certificate with private key that I exported as a .pfx file, the other one is a certificate that I saved including its certificate chain as a PKCS#7 file ("certchain.p7b").</p>
  
  <p>In C# I can now load the .pfx file with</p>
  
  <pre><code>  var cert = new X509Certificate2(myPfxFileStream); 
  </code></pre>
  
  <p>(myPfxFileStream is a <code>FileStream</code> opened to the .pfx File for reading), however trying the same thing with the PKCs#7 Certificate fails in a <code>CryptoGraphicException</code> "Der Indexwert ist ungültig" which translates to "invalid index value".</p>
  
  <p>I assume I have to parse PKCS#7 differently (it contains a chain, not a single certificate!), but how?</p>
  
  <p>(Oh, by the way: Currently I have no passwords on those certficiates)</p>