|
IAIK CMS/SMIME Toolkit API Documentation
Version 6.1 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.OutputStream
iaik.cms.ContentInfoOutputStream
public class ContentInfoOutputStream
This is an output stream version of a CMS ContentInfo structure. It uses indefinite constructed length encoding (so that the content data length must not be known in advance) and may be used in combination with any of the IAIK-CMS output stream implementations:
SignedDataOutputStream
EnvelopedDataOutputStream
EncryptedDataOutputStream
DigestedDataOutputStream
AuthenticatedDataOutputStream
CompressedDataOutputStream
ContentInfo ::= SEQUENCE {
contentType ContentType,
content
[0] EXPLICIT ANY DEFINED BY contentType }
ContentType ::= OBJECT IDENTIFIER
When using the output stream implementation of a CMS content type, first a
ContentInfoOutputStream has to be wrapped around the output
stream to which the CMS object shall be written (the ContentInfoOutputStream
has to write its headers to the stream at first, thus it must be created at
the "lowest" level). The following example uses a SignedDataOutputStream to create a CMS SignedData
object, pack it into a ContentInfo and write it encoded to an output
stream:
// the private key of the signer
PrivateKey signatureKey = ...
// the certificates of the signer
X509Certificate[] certificateChain = ...
// the input stream from which to read the data to be signed
InputStream dataInputStream = ...
// the output stream to which to write the signed data
OutputStream resultStream = ...
// first wrap a ContentInfoOutputStream around the resulting output stream
ContentInfoOutputStream contentInfoStream =
new ContentInfoOutputStream(ObjectID.cms_signedData, resultStream);
// create SignedDataOutputStream for the ContentInfoStream:
SignedDataOutputStream signedData =
new SignedDataOutputStream(contentInfoStream, SignedDataOutputStream.IMPLICIT);
// the further proceeding is same as above
// add the certificates
signedData.addCertificates(certificateChain);
// add a SignerInfo
X509Certificate signatureCert = certificateChain[0];
SignerInfo signerInfo = new SignerInfo(
new IssuerAndSerialNumber(signatureCert), AlgorithmID.sha256, signatureKey);
// define some attributes
Attribute[] attributes = {
new Attribute(new CMSContentType(ObjectID.cms_data)),
new Attribute(new SigningTime())
};
// set the attributes
signerInfo.setSignedAttributes(attributes);
// and add the new signer
signedData.addSignerInfo(signerInfo);
// write in the data to be signed
byte[] buffer = new byte[2048];
int bytesRead;
while ((bytesRead = dataInputStream.read(buffer)) != -1) {
signedData.write(buffer, 0, bytesRead);
}
// closing the stream add the signer infos and closes the underlying stream
signedData.close();
SignedDataOutputStream,
EnvelopedDataOutputStream,
EncryptedDataOutputStream,
DigestedDataOutputStream,
AuthenticatedDataOutputStream,
CompressedDataOutputStream| Constructor Summary | |
|---|---|
ContentInfoOutputStream(iaik.asn1.ObjectID type,
java.io.OutputStream out)
Creates a new ContentInfo output stream object. |
|
| Method Summary | |
|---|---|
void |
close()
Finishes the ContentInfo encoding and writes the final EOC bytes. |
void |
flush()
Flushes any internal data and calls flush of the underlying stream. |
iaik.asn1.ObjectID |
getContentType()
Returns the content type of this CMS ContentInfo. |
boolean |
isPassThroughClose()
Checks whether a call to close() will call close of the
underlying output stream |
void |
setPassThroughClose(boolean passThroughClose)
Setting this to true will cause close() to call
close of the underlying output stream. |
java.lang.String |
toString()
Returns a string giving some information about this CMS ContentInfo. |
void |
write(byte[] b)
Encodes and writes the given content data to the output stream. |
void |
write(byte[] b,
int off,
int len)
Encodes and writes the given content data to the output stream. |
void |
write(int b)
Encodes and writes the given content byte to the output stream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ContentInfoOutputStream(iaik.asn1.ObjectID type,
java.io.OutputStream out)
type - the content type of the included content (e.g. ObjectID.cms_signedData).out - the underlying output stream for writing.| Method Detail |
|---|
public void write(byte[] b,
int off,
int len)
throws java.io.IOException
write in class java.io.OutputStreamb - The data to be writtenoff - The start offset in the data array b.len - The number of bytes to write.
java.io.IOException - If an I/O error occurs.
public void write(byte[] b)
throws java.io.IOException
write in class java.io.OutputStreamb - The data to be written
java.io.IOException - If an I/O error occurs.
public void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamb - The data byte to be written
java.io.IOException - If an I/O error occurs.
public void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOException - If flushing the stream fails.
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in class java.io.OutputStreamjava.io.IOException - if an I/O error occurspublic boolean isPassThroughClose()
close() will call close of the
underlying output stream
true if a call to close() will call
close of the underlying output stream;
false if a call to close() will not close the
underlying stream.public void setPassThroughClose(boolean passThroughClose)
true will cause close() to call
close of the underlying output stream. If false,
a call to close() will not close the underlying stream.
passThroughClose - true to pass through close()
calls. false to not pass them through.public iaik.asn1.ObjectID getContentType()
public java.lang.String toString()
toString in class java.lang.Object
|
IAIK CMS/SMIME Toolkit API Documentation
Version 6.1 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
|
v6.1 (c) 2002 IAIK, (c) 2003 - 2025 SIC |
|