有没有什么很好的教程教你如何用bouncycastle对文件进行签名,并将其封装在asn1 pkcs7包中?
发布于 2011-06-23 03:29:52
过了一段时间,我发现了它是如何做到的,在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());https://stackoverflow.com/questions/6335928
复制相似问题