BouncyCastle中嵌套的PKCS7

时间:2017-12-20 08:02:04

标签: java encryption cryptography bouncycastle pkcs#7

我想在EnvelopedData中封装SignedData。 我正在使用BouncyCastle。 在看了一个例子后,我写了这样的东西:

 CMSSignedData signedData = gen.generate(new CMSProcessableByteArray(out.toByteArray()), true);


    FileInputStream inputStream = new FileInputStream(args[3]);

    CertificateFactory factory = CertificateFactory.getInstance("X.509", "BC");
    X509Certificate certificate = (X509Certificate) factory.generateCertificate(inputStream);

    CMSEnvelopedDataGenerator engen = new CMSEnvelopedDataGenerator();
    engen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(certificate).setProvider("BC"));
CMSEnvelopedData envelopedData =engen.generate(  new CMSProcessableByteArray(signedData.getEncoded()),
new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES256_CBC).setProvider("BC").build());

但我认为这是错误的。我在哪里可以指定ContentInfo的ContentType?我需要将EnvelopedData的内容类型指定为SignedData,但CMSSignedData类不能这样做。

0 个答案:

没有答案