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").
In C# I can now load the .pfx file with
var cert = new X509Certificate2(myPfxFileStream);
(myPfxFileStream is a FileStream
opened to the .pfx File for reading), however trying the same thing with the PKCs#7 Certificate fails in a CryptoGraphicException
"Der Indexwert ist ungültig" which translates to "invalid index value".
I assume I have to parse PKCS#7 differently (it contains a chain, not a single certificate!), but how?
(Oh, by the way: Currently I have no passwords on those certficiates)
To view certificates for the current userSelect Run from the Start menu, and then enter certmgr. msc. The Certificate Manager tool for the current user appears. To view your certificates, under Certificates - Current User in the left pane, expand the directory for the type of certificate you want to view.
In cryptography, PKCS #12 defines an archive file format for storing many cryptography objects as a single file. It is commonly used to bundle a private key with its X. 509 certificate or to bundle all the members of a chain of trust.
You will want to use the SignedCms
class in the System.Security.Cryptography.Pkcs
namespace.
This blog entry will show you how to use the class:
link update 2021: https://docs.microsoft.com/en-us/archive/blogs/shawnfa/enveloped-pkcs-7-signatures
original link: http://blogs.msdn.com/shawnfa/archive/2006/02/27/539990.aspx
You basically will call the Decode
method, passing the bytes representing the PKCS file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With