Class CMSEnvelopedDataStreamGenerator

java.lang.Object
org.bouncycastle.cms.CMSEnvelopedGenerator
org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator

public class CMSEnvelopedDataStreamGenerator extends CMSEnvelopedGenerator
General class for generating a CMS enveloped-data message stream.

A simple example of usage.

      CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();

      edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(recipientCert).setProvider("BC"));

      ByteArrayOutputStream  bOut = new ByteArrayOutputStream();

      OutputStream out = edGen.open(
                              bOut, new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC)
                                              .setProvider("BC").build());
      out.write(data);

      out.close();
 

Stream handling note:

  • The returned OutputStream must be closed to finalize the CMS structure.
  • Closing the returned stream does not close the underlying OutputStream passed to open().
  • Callers are responsible for closing the underlying OutputStream separately. If the underlying OutputStream is a buffering encoder whose tail state only flushes on close (e.g. Apache Commons Base64OutputStream), failing to close it will cause the encoded output to be truncated.