Class CMSSignedDataStreamGenerator


  • public class CMSSignedDataStreamGenerator
    extends CMSSignedGenerator
    General class for generating a pkcs7-signature message stream.

    A simple example of usage.

          X509Certificate signCert = ...
          certList.add(signCert);
    
          Store           certs = new JcaCertStore(certList);
          ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(signKP.getPrivate());
    
          CMSSignedDataStreamGenerator gen = new CMSSignedDataStreamGenerator();
      
          gen.addSignerInfoGenerator(
                    new JcaSignerInfoGeneratorBuilder(
                         new JcaDigestCalculatorProviderBuilder().setProvider("BC").build())
                         .build(sha1Signer, signCert));
    
          gen.addCertificates(certs);
      
          OutputStream sigOut = gen.open(bOut);
      
          sigOut.write("Hello World!".getBytes());
          
          sigOut.close();
     
    • Constructor Detail

      • CMSSignedDataStreamGenerator

        public CMSSignedDataStreamGenerator()
        base constructor
    • Method Detail

      • setBufferSize

        public void setBufferSize​(int bufferSize)
        Set the underlying string size for encapsulated data
        Parameters:
        bufferSize - length of octet strings to buffer the data.
      • open

        public java.io.OutputStream open​(java.io.OutputStream out)
                                  throws java.io.IOException
        generate a signed object that for a CMS Signed Data object using the given provider.
        Throws:
        java.io.IOException
      • open

        public java.io.OutputStream open​(java.io.OutputStream out,
                                         boolean encapsulate)
                                  throws java.io.IOException
        generate a signed object that for a CMS Signed Data object using the given provider - if encapsulate is true a copy of the message will be included in the signature with the default content type "data".
        Throws:
        java.io.IOException
      • open

        public java.io.OutputStream open​(java.io.OutputStream out,
                                         boolean encapsulate,
                                         java.io.OutputStream dataOutputStream)
                                  throws java.io.IOException
        generate a signed object that for a CMS Signed Data object using the given provider - if encapsulate is true a copy of the message will be included in the signature with the default content type "data". If dataOutputStream is non null the data being signed will be written to the stream as it is processed.
        Parameters:
        out - stream the CMS object is to be written to.
        encapsulate - true if data should be encapsulated.
        dataOutputStream - output stream to copy the data being signed to.
        Throws:
        java.io.IOException
      • open

        public java.io.OutputStream open​(org.bouncycastle.asn1.ASN1ObjectIdentifier eContentType,
                                         java.io.OutputStream out,
                                         boolean encapsulate)
                                  throws java.io.IOException
        generate a signed object that for a CMS Signed Data object using the given provider - if encapsulate is true a copy of the message will be included in the signature. The content type is set according to the OID represented by the string signedContentType.
        Throws:
        java.io.IOException
      • open

        public java.io.OutputStream open​(org.bouncycastle.asn1.ASN1ObjectIdentifier eContentType,
                                         java.io.OutputStream out,
                                         boolean encapsulate,
                                         java.io.OutputStream dataOutputStream)
                                  throws java.io.IOException
        generate a signed object that for a CMS Signed Data object using the given provider - if encapsulate is true a copy of the message will be included in the signature. The content type is set according to the OID represented by the string signedContentType.
        Parameters:
        eContentType - OID for data to be signed.
        out - stream the CMS object is to be written to.
        encapsulate - true if data should be encapsulated.
        dataOutputStream - output stream to copy the data being signed to.
        Throws:
        java.io.IOException
      • getDigestAlgorithms

        public java.util.List<org.bouncycastle.asn1.x509.AlgorithmIdentifier> getDigestAlgorithms()
        Return a list of the current Digest AlgorithmIdentifiers applying to the next signature.
        Returns:
        a list of the Digest AlgorithmIdentifiers