diff --git a/src/main/java/com/siemens/pki/cmpracomponent/cryptoservices/CmsEncryptorBase.java b/src/main/java/com/siemens/pki/cmpracomponent/cryptoservices/CmsEncryptorBase.java index 7104090c..d82ae951 100644 --- a/src/main/java/com/siemens/pki/cmpracomponent/cryptoservices/CmsEncryptorBase.java +++ b/src/main/java/com/siemens/pki/cmpracomponent/cryptoservices/CmsEncryptorBase.java @@ -17,13 +17,11 @@ */ package com.siemens.pki.cmpracomponent.cryptoservices; -import com.siemens.pki.cmpracomponent.configuration.CkgContext; -import com.siemens.pki.cmpracomponent.util.ConfigLogger; import java.io.IOException; import java.security.NoSuchAlgorithmException; + +import org.bouncycastle.asn1.ASN1Object; import org.bouncycastle.asn1.cms.EnvelopedData; -import org.bouncycastle.asn1.cms.SignedData; -import org.bouncycastle.cms.CMSAlgorithm; import org.bouncycastle.cms.CMSEnvelopedData; import org.bouncycastle.cms.CMSEnvelopedDataGenerator; import org.bouncycastle.cms.CMSException; @@ -31,6 +29,9 @@ import org.bouncycastle.cms.RecipientInfoGenerator; import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder; +import com.siemens.pki.cmpracomponent.configuration.CkgContext; +import com.siemens.pki.cmpracomponent.util.ConfigLogger; + /** * base class for CMS data encryption */ @@ -73,17 +74,14 @@ public EnvelopedData encrypt(final byte[] msg) throws CMSException, NoSuchAlgori /** * encrypt the data * - * @param data signed data to encrypt + * @param asn1Object ASN.1 object to encrypt * @return encrypted data * @throws CMSException in case of an CMS processing error * @throws IOException in case of ASN.1 encoding error + * @throws NoSuchAlgorithmException if getContentEncryptionAlg in config is + * unknown */ - public EnvelopedData encrypt(final SignedData data) throws CMSException, IOException { - final CMSEnvelopedData cmsEnvData = envGen.generate( - new CMSProcessableByteArray(data.getEncoded()), - new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES256_CBC) - .setProvider(CertUtility.getBouncyCastleProvider()) - .build()); - return EnvelopedData.getInstance(cmsEnvData.toASN1Structure().getContent()); + public EnvelopedData encrypt(final ASN1Object asn1Object) throws CMSException, IOException, NoSuchAlgorithmException { + return encrypt(asn1Object.getEncoded()); } }