是否有任何关于如何使用 bouncycaSTLe 对文件进行签名并将其包装在 asn1 pkcs7 包中的好教程?
最佳答案
一段时间后,我在 bouncyCaSTLe 应用程序中的示例中找到了它是如何完成的。
它实际上比我在 IText 中发现的要简单和直接(没有去掉框架本身的友好性)。
代码是这样的:
AsymmetricCipherKeyPair signaturePair;
X509Certificate signatureCert;
IList certList = new ArrayList();
IList crlList = new ArrayList();
CmsProcessable msg = new CmsProcessableByteArray(Encoding.ASCII.GetBytes("I hate hello world!"));
certList.Add(signatureCert);
certList.Add(OrigCert);
crlList.Add(SignCrl);
IX509Store x509Certs = X509StoreFactory.Create(
"Certificate/Collection",
new X509CollectionStoreParameters(certList));
IX509Store x509Crls = X509StoreFactory.Create(
"CRL/Collection",
new X509CollectionStoreParameters(crlList));
CmsSignedDataGenerator gen = new CmsSignedDataGenerator();
gen.AddSigner(signaturePair.Private, signatureCert, CmsSignedDataGenerator.DigestSha1);
gen.AddCertificates(x509Certs);
gen.AddCrls(x509Crls);
CmsSignedData signedData = gen.Generate(msg, true);
//saving in BER encoding
Stream stream = new MemoryStream(signedData.GetEncoded());
关于c# - 签名和创建 asn1 签名消息 - BouncycaSTLe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6335928/