Bouncy Castle Cryptography 1.30

org.bouncycastle.cms
Class CMSSignedDataStreamGenerator

java.lang.Object
  extended by org.bouncycastle.cms.CMSSignedDataStreamGenerator

public class CMSSignedDataStreamGenerator
extends java.lang.Object

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
static java.lang.String DATA
          Default type for the signed data.
static java.lang.String DIGEST_GOST3411
           
static java.lang.String DIGEST_MD5
           
static java.lang.String DIGEST_SHA1
           
static java.lang.String DIGEST_SHA224
           
static java.lang.String DIGEST_SHA256
           
static java.lang.String DIGEST_SHA384
           
static java.lang.String DIGEST_SHA512
           
static java.lang.String ENCRYPTION_DSA
           
static java.lang.String ENCRYPTION_ECGOST3410
           
static java.lang.String ENCRYPTION_GOST3410
           
static java.lang.String ENCRYPTION_RSA
           
 
Constructor Summary
CMSSignedDataStreamGenerator()
          base constructor
 
Method Summary
 void addCertificatesAndCRLs(java.security.cert.CertStore certStore)
          add the certificates and CRLs contained in the given CertStore to the pool that will be included in the encoded signature block.
 void addSigner(java.security.PrivateKey key, java.security.cert.X509Certificate cert, java.lang.String digestOID, org.bouncycastle.asn1.cms.AttributeTable signedAttr, org.bouncycastle.asn1.cms.AttributeTable unsignedAttr, java.lang.String sigProvider)
          add a signer with extra signed/unsigned attributes.
 void addSigner(java.security.PrivateKey key, java.security.cert.X509Certificate cert, java.lang.String digestOID, java.lang.String sigProvider)
          add a signer - no attributes other than the default ones will be provided here.
 void addSigners(SignerInformationStore signerStore)
          Add a store of precalculated signers to the generator.
 java.io.OutputStream open(java.io.OutputStream out)
          generate a signed object that for a CMS Signed Data object using the given provider.
 java.io.OutputStream open(java.io.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".
 java.io.OutputStream open(java.io.OutputStream out, java.lang.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.
 void setBufferSize(int bufferSize)
          Set the underlying string size for encapsulated data
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATA

public static final java.lang.String DATA
Default type for the signed data.


DIGEST_SHA1

public static final java.lang.String DIGEST_SHA1
See Also:
Constant Field Values

DIGEST_SHA224

public static final java.lang.String DIGEST_SHA224

DIGEST_SHA256

public static final java.lang.String DIGEST_SHA256

DIGEST_SHA384

public static final java.lang.String DIGEST_SHA384

DIGEST_SHA512

public static final java.lang.String DIGEST_SHA512

DIGEST_MD5

public static final java.lang.String DIGEST_MD5
See Also:
Constant Field Values

DIGEST_GOST3411

public static final java.lang.String DIGEST_GOST3411

ENCRYPTION_RSA

public static final java.lang.String ENCRYPTION_RSA
See Also:
Constant Field Values

ENCRYPTION_DSA

public static final java.lang.String ENCRYPTION_DSA
See Also:
Constant Field Values

ENCRYPTION_GOST3410

public static final java.lang.String ENCRYPTION_GOST3410

ENCRYPTION_ECGOST3410

public static final java.lang.String ENCRYPTION_ECGOST3410
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.

addSigner

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

Throws:
java.security.NoSuchProviderException
java.security.NoSuchAlgorithmException
java.security.InvalidKeyException

addSigner

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

Throws:
java.security.NoSuchProviderException
java.security.NoSuchAlgorithmException
java.security.InvalidKeyException

addSigners

public void addSigners(SignerInformationStore signerStore)
Add a store of precalculated signers to the generator.

Parameters:
signerStore -

addCertificatesAndCRLs

public void addCertificatesAndCRLs(java.security.cert.CertStore certStore)
                            throws java.security.cert.CertStoreException,
                                   CMSException
add the certificates and CRLs contained in the given CertStore to the pool that will be included in the encoded signature block.

Note: this assumes the CertStore will support null in the get methods.

Throws:
java.security.cert.CertStoreException
CMSException

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,
                                 java.lang.String signedContentType,
                                 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

Bouncy Castle Cryptography 1.30