List of usage examples for org.bouncycastle.cms.bc BcCMSContentEncryptorBuilder build
public OutputEncryptor build() throws CMSException
From source file:org.ejbca.util.CMS.java
License:Open Source License
/** * @param is data to be encrypted/*from w w w . j a va 2 s.co m*/ * @param os encrypted data * @param cert certificate with the public key to be used for the encryption * @param symmAlgOid the symmetric encryption algorithm to use, for example CMSEnvelopedGenerator.AES128_CBC * @throws Exception */ public static void encrypt(final InputStream is, final OutputStream os, final X509Certificate cert, final String symmAlgOid) throws Exception { final InputStream bis = new BufferedInputStream(is, bufferSize); final OutputStream bos = new BufferedOutputStream(os, bufferSize); final CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator(); edGen.addRecipientInfoGenerator( new JceKeyTransRecipientInfoGenerator("hej".getBytes(), cert.getPublicKey())); BcCMSContentEncryptorBuilder bcCMSContentEncryptorBuilder = new BcCMSContentEncryptorBuilder( new ASN1ObjectIdentifier(symmAlgOid)); final OutputStream out = edGen.open(bos, bcCMSContentEncryptorBuilder.build()); fromInToOut(bis, out); bos.close(); os.close(); }