How to retrieve certificates from a pfx file with c#? -
i've been googling around half day looking way read .pfx
file , import certificates certstore.
so far, able read .pfx
file x509certifcate
, able import 1 certificate within .pfx
file. far good, there 3 certificates in .pfx
file , when loading .pfx
x509certificate
, not able see other 2 certificates.
the certificate exported
*personal information exchange - pkcs #12 (.pfx)
include certificates in certification path if possible
enable strong protection (requires ie 5.0, nt 4.0 sp4 or above)
those options selected when exporting certificate(s). know there 3 certificates because manually go certstore (mmc) , import personal folder myself.
you should able collection object containing certs in .pfx file using x509certificate2collection
class... here's c# example code:
string certpath = <your pfx file path>; string certpass = <your password>; // create collection object , populate using pfx file x509certificate2collection collection = new x509certificate2collection(); collection.import(certpath, certpass, x509keystorageflags.persistkeyset);
then can iterate on collection:
foreach (x509certificate2 cert in collection) { console.writeline("subject is: '{0}'", cert.subject); console.writeline("issuer is: '{0}'", cert.issuer); // import certificates x509store objects }
depending on type of certificate (client cert, intermediate ca cert, root ca) you'll need open proper cert store (as x509store
object) import it.
check out x509store
docs:
http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509store.aspx
and different members in storename
enumeration:
http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.storename.aspx
from understand, want use storename.my
client certificates contain private key, storename.certificateauthority
intermediate ca certs, , storename.root
root ca certs.
Comments
Post a Comment