【发布时间】:2016-12-05 19:36:38
【问题描述】:
经过无数个小时的挣扎,我终于有了当前的工作代码,可以使用 JCE/JCA 生成带有收件人信息的 CMS 封装 (RSA-OAEP / PKCS#1) 数据:
String digest = "SHA-256";
String mgfDigest = "SHA-256";
// Data to encrypt
CMSTypedData msg = new CMSProcessableByteArray(data);
// Generator for my CMS enveloped data
CMSEnvelopedDataGenerator envelopedDataGen = new CMSEnvelopedDataGenerator();
// Recipient Info Stuff
JcaAlgorithmParametersConverter paramsConverter = new JcaAlgorithmParametersConverter();
OAEPParameterSpec oaepSpec = new OAEPParameterSpec(digest, "MGF1", new MGF1ParameterSpec(mgfDigest), PSource.PSpecified.DEFAULT);
AlgorithmIdentifier oaepAlgId = paramsConverter.getAlgorithmIdentifier(PKCSObjectIdentifiers.id_RSAES_OAEP, oaepSpec);
envelopedDataGen.addRecipientInfoGenerator(
new JceKeyTransRecipientInfoGenerator(
getCert(),
oaepAlgId).setProvider("BC"));
/*
* Generate CMS-Data
* CMSOutputEncryptor is my own Class implementing OutputEncryptor
*/
CMSEnvelopedData ed = envelopedDataGen.generate(
msg,
new CMSOutputEncryptor());
byte[] encoded = ed.getEncoded();
这按预期工作,但因为它使用 JCE,我的客户需要安装无限强度 api 才能使用此代码。我更喜欢一种方法来克服这些需求,因为我的大多数客户的手指都是拇指......
也许有人可以给我看一段代码,它使用纯 BouncyCastle 方式来做同样的事情,这样就不需要安装无限强度 api?
【问题讨论】:
标签: java bouncycastle pkcs#1