首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >签名和创建asn1签名消息- Bouncycastle

签名和创建asn1签名消息- Bouncycastle
EN

Stack Overflow用户
提问于 2011-06-14 04:29:35
回答 1查看 3.3K关注 0票数 5

有没有什么很好的教程教你如何用bouncycastle对文件进行签名,并将其封装在asn1 pkcs7包中?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-23 03:29:52

过了一段时间,我发现了它是如何做到的,在bouncyCastle应用程序内部的示例中。

实际上,它比我在IText中发现的更简单、更直接(没有去掉框架本身的亲和性)。

代码类似于:

代码语言:javascript
复制
        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());
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6335928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档