How to read Pkcs # 7 certificate chain from file / stream in C #?

I have two certificates that I saved to disk. One of them is a private key certificate that I exported as a .pfx file, the other is a certificate that I saved, including its certificate chain as a PKCS # 7 file ("certchain.p7b").

In C #, I can upload a .pfx file using

  var cert = new X509Certificate2(myPfxFileStream); 

(myPfxFileStream is FileStreamopen for reading by the .pfx file), but try to do the same with the PKCs # 7 certificate in CryptoGraphicException"Der Indexwert ist ungültig", which translates to "invalid index value".

I assume that I should deal with PKCS # 7 (it contains a chain, not one certificate!), But how?

(Oh, by the way: I currently do not have passwords on these certficiates)

+5
source share
1 answer

You will want to use the class SignedCmsin System.Security.Cryptography.Pkcs.

This blog post will show you how to use the class:

http://blogs.msdn.com/shawnfa/archive/2006/02/27/539990.aspx

You basically call the method Decodeby passing bytes representing the PKCS file.

+7
source

All Articles