|
|
|
@ -127,6 +127,7 @@ import org.bouncycastle.cms.RecipientInfoGenerator;
|
|
|
|
|
import org.bouncycastle.cms.SignerInfoGenerator;
|
|
|
|
|
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder;
|
|
|
|
|
import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder;
|
|
|
|
|
import org.bouncycastle.cms.jcajce.JceKeyAgreeRecipientInfoGenerator;
|
|
|
|
|
import org.bouncycastle.cms.jcajce.JceKeyTransRecipientInfoGenerator;
|
|
|
|
|
import org.bouncycastle.operator.ContentSigner;
|
|
|
|
|
import org.bouncycastle.operator.DigestCalculatorProvider;
|
|
|
|
@ -2832,8 +2833,16 @@ public class FragmentCompose extends FragmentBase {
|
|
|
|
|
// Encrypt
|
|
|
|
|
CMSEnvelopedDataGenerator cmsEnvelopedDataGenerator = new CMSEnvelopedDataGenerator();
|
|
|
|
|
if ("EC".equals(privkey.getAlgorithm())) {
|
|
|
|
|
JceKeyAgreeRecipientInfoGenerator gen = new JceKeyAgreeRecipientInfoGenerator(
|
|
|
|
|
CMSAlgorithm.ECDH_SHA256KDF,
|
|
|
|
|
privkey,
|
|
|
|
|
chain[0].getPublicKey(),
|
|
|
|
|
CMSAlgorithm.AES128_WRAP);
|
|
|
|
|
for (X509Certificate cert : certs)
|
|
|
|
|
gen.addRecipient(cert);
|
|
|
|
|
cmsEnvelopedDataGenerator.addRecipientInfoGenerator(gen);
|
|
|
|
|
// https://security.stackexchange.com/a/53960
|
|
|
|
|
throw new IllegalArgumentException("ECDSA cannot be used for encryption");
|
|
|
|
|
// throw new IllegalArgumentException("ECDSA cannot be used for encryption");
|
|
|
|
|
} else {
|
|
|
|
|
for (X509Certificate cert : certs) {
|
|
|
|
|
RecipientInfoGenerator gen = new JceKeyTransRecipientInfoGenerator(cert);
|
|
|
|
|