【问题标题】:Signing and creating a asn1 signedmessage - Bouncycastle签名和创建 asn1 签名消息 - Bouncycastle
【发布时间】:2011-06-13 20:29:34
【问题描述】:

有没有关于如何签署文件并使用 bouncycastle 将其包装在 asn1 pkcs7 包中的好的教程?

【问题讨论】:

    标签: c# bouncycastle asn.1 pkcs#7


    【解决方案1】:

    一段时间后,我在 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());
    

    【讨论】:

      猜你喜欢
      • 2020-07-06
      • 2012-11-11
      • 1970-01-01
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 2019-01-13
      • 2011-08-04
      • 2013-05-15
      相关资源
      最近更新 更多