Top Description Inners Fields Constructors Methods
org.bouncycastle.cms

public Class CMSSignedDataStreamGenerator

extends CMSSignedGenerator
Class Inheritance
Imports
java.io.IOException, .OutputStream, java.util.ArrayList, .HashSet, .Iterator, .List, .Set, org.bouncycastle.asn1.ASN1EncodableVector, .ASN1Integer, .ASN1ObjectIdentifier, .ASN1Set, .ASN1TaggedObject, .BERSequenceGenerator, .BERTaggedObject, .DERSet, org.bouncycastle.asn1.cms.CMSObjectIdentifiers, .SignerInfo, org.bouncycastle.asn1.x509.AlgorithmIdentifier, org.bouncycastle.operator.DigestAlgorithmIdentifierFinder

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();

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private int
Inherited from org.bouncycastle.cms.CMSSignedGenerator:
_signerscertscrlsDATADIGEST_GOST3411DIGEST_MD5DIGEST_RIPEMD128DIGEST_RIPEMD160DIGEST_RIPEMD256DIGEST_SHA1DIGEST_SHA224DIGEST_SHA256DIGEST_SHA384DIGEST_SHA512digestAlgIdFinderdigestsENCRYPTION_DSAENCRYPTION_ECDSAENCRYPTION_ECGOST3410ENCRYPTION_ECGOST3410_2012_256ENCRYPTION_ECGOST3410_2012_512ENCRYPTION_GOST3410ENCRYPTION_RSAENCRYPTION_RSA_PSSsignerGens

Constructor Summary

AccessConstructor and Description
public
CMSSignedDataStreamGenerator()

base constructor

public
CMSSignedDataStreamGenerator(DigestAlgorithmIdentifierFinder digestAlgIdFinder)

base constructor with a custom DigestAlgorithmIdentifierFinder

Method Summary

Modifier and TypeMethod and Description
private ASN1Integer
private boolean
checkForVersion3(List<E> signerInfos, List<E> signerInfoGens)

public List<AlgorithmIdentifier>

Returns:

a list of the Digest AlgorithmIdentifiers
getDigestAlgorithms
()

Return a list of the current Digest AlgorithmIdentifiers applying to the next signature.

public OutputStream
open(OutputStream out)

generate a signed object that for a CMS Signed Data object using the given provider.

public 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".

public OutputStream
open(OutputStream
stream the CMS object is to be written to.
out
,
boolean
true if data should be encapsulated.
encapsulate
,
OutputStream
output stream to copy the data being signed to.
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".

public OutputStream
open(ASN1ObjectIdentifier eContentType, 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.

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

public void
setBufferSize(int
length of octet strings to buffer the data.
bufferSize
)

Set the underlying string size for encapsulated data

Inherited from org.bouncycastle.cms.CMSSignedGenerator:
addAttributeCertificateaddAttributeCertificatesaddCertificateaddCertificatesaddCRLaddCRLsaddOtherRevocationInfoaddOtherRevocationInfoaddSignerInfoGeneratoraddSignersgetBaseParametersgetGeneratedDigests

Field Detail

_bufferSizeback to summary
private int _bufferSize

Constructor Detail

CMSSignedDataStreamGeneratorback to summary
public CMSSignedDataStreamGenerator()

base constructor

CMSSignedDataStreamGeneratorback to summary
public CMSSignedDataStreamGenerator(DigestAlgorithmIdentifierFinder digestAlgIdFinder)

base constructor with a custom DigestAlgorithmIdentifierFinder

Method Detail

calculateVersionback to summary
private ASN1Integer calculateVersion(ASN1ObjectIdentifier contentOid)
checkForVersion3back to summary
private boolean checkForVersion3(List<E> signerInfos, List<E> signerInfoGens)
getDigestAlgorithmsback to summary
public List<AlgorithmIdentifier> getDigestAlgorithms()

Return a list of the current Digest AlgorithmIdentifiers applying to the next signature.

Returns:List<AlgorithmIdentifier>

a list of the Digest AlgorithmIdentifiers

openback to summary
public OutputStream open(OutputStream out) throws IOException

generate a signed object that for a CMS Signed Data object using the given provider.

openback to summary
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".

openback to summary
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:OutputStream

stream the CMS object is to be written to.

encapsulate:boolean

true if data should be encapsulated.

dataOutputStream:OutputStream

output stream to copy the data being signed to.

openback to summary
public OutputStream open(ASN1ObjectIdentifier eContentType, 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. The content type is set according to the OID represented by the string signedContentType.

openback to summary
public OutputStream open(ASN1ObjectIdentifier eContentType, 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. The content type is set according to the OID represented by the string signedContentType.

Parameters
eContentType:ASN1ObjectIdentifier

OID for data to be signed.

out:OutputStream

stream the CMS object is to be written to.

encapsulate:boolean

true if data should be encapsulated.

dataOutputStream:OutputStream

output stream to copy the data being signed to.

setBufferSizeback to summary
public void setBufferSize(int bufferSize)

Set the underlying string size for encapsulated data

Parameters
bufferSize:int

length of octet strings to buffer the data.

org.bouncycastle.cms back to summary

private Class CMSSignedDataStreamGenerator.CmsSignedDataOutputStream

extends OutputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private ASN1ObjectIdentifier
private BERSequenceGenerator
private OutputStream
private BERSequenceGenerator
private BERSequenceGenerator

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.
public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.
public void
write(byte[]
the data.
bytes
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
public void
write(byte[]
the data.
bytes
)

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.
Inherited from java.io.OutputStream:
flushnullOutputStream

Field Detail

_contentOIDback to summary
private ASN1ObjectIdentifier _contentOID
_eiGenback to summary
private BERSequenceGenerator _eiGen
_outback to summary
private OutputStream _out
_sGenback to summary
private BERSequenceGenerator _sGen
_sigGenback to summary
private BERSequenceGenerator _sigGen

Constructor Detail

CmsSignedDataOutputStreamback to summary
public CmsSignedDataOutputStream(OutputStream out, ASN1ObjectIdentifier contentOID, BERSequenceGenerator sGen, BERSequenceGenerator sigGen, BERSequenceGenerator eiGen)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(byte[] bytes, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
bytes:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
writeback to summary
public void write(byte[] bytes) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length).

Parameters
bytes:byte[]

the data.

Exceptions
IOException:
if an I/O error occurs.