org.bouncycastle.cms

Class CMSSignedDataStreamGenerator


public class CMSSignedDataStreamGenerator
extends CMSSignedGenerator

General class for generating a pkcs7-signature message stream.

A simple example of usage.

      CertStore                    certs...
      CMSSignedDataStreamGenerator gen = new CMSSignedDataStreamGenerator();
  
      gen.addSigner(privateKey, cert, CMSSignedDataStreamGenerator.DIGEST_SHA1, "BC");
  
      gen.addCertificatesAndCRLs(certs);
  
      OutputStream sigOut = gen.open(bOut);
  
      sigOut.write("Hello World!".getBytes());
      
      sigOut.close();
 

Field Summary

Fields inherited from class org.bouncycastle.cms.CMSSignedGenerator

DATA, DIGEST_GOST3411, DIGEST_MD5, DIGEST_RIPEMD128, DIGEST_RIPEMD160, DIGEST_RIPEMD256, DIGEST_SHA1, DIGEST_SHA224, DIGEST_SHA256, DIGEST_SHA384, DIGEST_SHA512, ENCRYPTION_DSA, ENCRYPTION_ECDSA, ENCRYPTION_ECGOST3410, ENCRYPTION_GOST3410, ENCRYPTION_RSA, ENCRYPTION_RSA_PSS, _certs, _crls, _digests, _signers, rand

Constructor Summary

CMSSignedDataStreamGenerator()
base constructor
CMSSignedDataStreamGenerator(SecureRandom rand)
constructor allowing specific source of randomness

Method Summary

void
addSigner(PrivateKey key, X509Certificate cert, String digestOID, AttributeTable signedAttr, AttributeTable unsignedAttr, String sigProvider)
add a signer with extra signed/unsigned attributes.
void
addSigner(PrivateKey key, X509Certificate cert, String digestOID, String sigProvider)
add a signer - no attributes other than the default ones will be provided here.
void
addSigner(PrivateKey key, X509Certificate cert, String digestOID, CMSAttributeTableGenerator signedAttrGenerator, CMSAttributeTableGenerator unsignedAttrGenerator, String sigProvider)
OutputStream
open(OutputStream out)
generate a signed object that for a CMS Signed Data object using the given provider.
OutputStream
open(OutputStream out, String signedContentType, boolean encapsulate)
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.
OutputStream
open(OutputStream out, String signedContentType, boolean encapsulate, OutputStream dataOutputStream)
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.
OutputStream
open(OutputStream out, boolean encapsulate)
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".
OutputStream
open(OutputStream out, boolean encapsulate, OutputStream dataOutputStream)
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".
void
setBufferSize(int bufferSize)
Set the underlying string size for encapsulated data

Methods inherited from class org.bouncycastle.cms.CMSSignedGenerator

addAttributeCertificates, addCertificatesAndCRLs, addSigners, getAttributeSet, getBaseParameters, getEncAlgorithmIdentifier, getEncOID, getGeneratedDigests

Constructor Details

CMSSignedDataStreamGenerator

public CMSSignedDataStreamGenerator()
base constructor

CMSSignedDataStreamGenerator

public CMSSignedDataStreamGenerator(SecureRandom rand)
constructor allowing specific source of randomness
Parameters:
rand - instance of SecureRandom to use

Method Details

addSigner

public void addSigner(PrivateKey key,
                      X509Certificate cert,
                      String digestOID,
                      AttributeTable signedAttr,
                      AttributeTable unsignedAttr,
                      String sigProvider)
            throws NoSuchAlgorithmException,
                   NoSuchProviderException,
                   InvalidKeyException
add a signer with extra signed/unsigned attributes.

addSigner

public void addSigner(PrivateKey key,
                      X509Certificate cert,
                      String digestOID,
                      String sigProvider)
            throws NoSuchAlgorithmException,
                   NoSuchProviderException,
                   InvalidKeyException
add a signer - no attributes other than the default ones will be provided here.

addSigner

public void addSigner(PrivateKey key,
                      X509Certificate cert,
                      String digestOID,
                      CMSAttributeTableGenerator signedAttrGenerator,
                      CMSAttributeTableGenerator unsignedAttrGenerator,
                      String sigProvider)
            throws NoSuchAlgorithmException,
                   NoSuchProviderException,
                   InvalidKeyException

open

public OutputStream open(OutputStream out)
            throws IOException
generate a signed object that for a CMS Signed Data object using the given provider.

open

public OutputStream open(OutputStream out,
                         String signedContentType,
                         boolean encapsulate)
            throws 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.

open

public OutputStream open(OutputStream out,
                         String signedContentType,
                         boolean encapsulate,
                         OutputStream dataOutputStream)
            throws 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:
out - stream the CMS object is to be written to.
signedContentType - OID for data to be signed.
encapsulate - true if data should be encapsulated.
dataOutputStream - output stream to copy the data being signed to.

open

public OutputStream open(OutputStream out,
                         boolean encapsulate)
            throws 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".

open

public OutputStream open(OutputStream out,
                         boolean encapsulate,
                         OutputStream dataOutputStream)
            throws 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.

setBufferSize

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