如何从.p7b文件获取证书

时间:2015-10-09 09:40:21

标签: c# bouncycastle pkcs#7

任何人都可以帮助如何从C#和BouncyCastle中的.p7b文件中提取证书吗?

1 个答案:

答案 0 :(得分:0)

var certificateStore = new CmsSignedData(new FileStream("chain.p7b", FileMode.Open));
IX509Store x509Certs = certificateStore.GetCertificates("Collection");
ArrayList a = new ArrayList(x509Certs.GetMatches(null));
X509Certificate signerCert = (X509Certificate) a[0];

var gen = new CmsSignedDataGenerator();
gen.AddCertificates(x509Certs);
gen.AddSigner(_privateKey, signerCert, CmsSignedGenerator.DigestSha1);

CmsProcessable msg = new CmsProcessableByteArray(Encoding.ASCII.GetBytes(FullUnsignedMessage));

CmsSignedData signedData = gen.Generate(msg, true);