Top Description Inners Fields Constructors Methods
org.bouncycastle.mime.smime

public Class SMIMESignedWriter

extends MimeWriter
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .IOException, .OutputStream, java.math.BigInteger, java.security.SecureRandom, java.util.Collections, .HashMap, .Iterator, .LinkedHashMap, .List, .Map, .Set, .TreeSet, org.bouncycastle.asn1.x509.AlgorithmIdentifier, org.bouncycastle.cert.X509CertificateHolder, org.bouncycastle.cms.CMSAlgorithm, .CMSException, .CMSSignedDataStreamGenerator, .SignerInfoGenerator, org.bouncycastle.mime.Headers, .MimeWriter, org.bouncycastle.mime.encoding.Base64OutputStream, org.bouncycastle.util.Store, .Strings

Writer for SMIME Signed objects.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
private class

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final OutputStream
public static final Map<K, V>
public static final Map<K, V>
private final CMSSignedDataStreamGenerator
public static final Map<K, V>
Inherited from org.bouncycastle.mime.MimeWriter:
headers

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public OutputStream

Returns:

an output stream for data to be signed to be written to.
getContentStream
()

Implements abstract org.bouncycastle.mime.MimeWriter.getContentStream.

Return a content stream for the signer - note data written to this stream needs to properly canonicalised if necessary.
Inherited from org.bouncycastle.mime.MimeWriter:
getHeadersmapToLines

Field Detail

boundaryback to summary
private final String boundary
contentTransferEncodingback to summary
private final String contentTransferEncoding
mimeOutback to summary
private final OutputStream mimeOut
RFC3851_MICALGSback to summary
public static final Map<K, V> RFC3851_MICALGS
RFC5751_MICALGSback to summary
public static final Map<K, V> RFC5751_MICALGS
sigGenback to summary
private final CMSSignedDataStreamGenerator sigGen
STANDARD_MICALGSback to summary
public static final Map<K, V> STANDARD_MICALGS

Constructor Detail

SMIMESignedWriterback to summary
private SMIMESignedWriter(SMIMESignedWriter.Builder builder, Map<String, String> headers, String boundary, OutputStream mimeOut)

Method Detail

getContentStreamback to summary
public OutputStream getContentStream() throws IOException

Implements abstract org.bouncycastle.mime.MimeWriter.getContentStream.

Return a content stream for the signer - note data written to this stream needs to properly canonicalised if necessary.

Returns:OutputStream

an output stream for data to be signed to be written to.

Exceptions
IOException:
on a stream error.
org.bouncycastle.mime.smime back to summary

public Class SMIMESignedWriter.Builder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv String
private static final String[]
private static final String[]
private final boolean
private static final String[]
private static final String[]
private final Map<String, String>
private final Map<K, V>
private final CMSSignedDataStreamGenerator

Constructor Summary

AccessConstructor and Description
public
public
Builder(boolean encapsulated)

Method Summary

Modifier and TypeMethod and Description
private void
addBoundary(StringBuffer header, String boundary)

public SMIMESignedWriter.Builder
public SMIMESignedWriter.Builder
addCertificates(Store<T> certificates)

private void
addHashHeader(StringBuffer header, List<E> signers)

public SMIMESignedWriter.Builder

Returns:

the current Builder instance.
addSignerInfoGenerator
(SignerInfoGenerator
a generator for a signer info object.
signerGenerator
)

Add a generator to produce the signer info required.

public SMIMESignedWriter
private String
public SMIMESignedWriter.Builder

Returns:

the current Builder instance.
withHeader
(String
name of the MIME header.
headerName
,
String
value of the MIME header.
headerValue
)

Specify a MIME header (name, value) pair for this builder.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentTransferEncodingback to summary
pack-priv String contentTransferEncoding
detHeadersback to summary
private static final String[] detHeaders
detValuesback to summary
private static final String[] detValues
encapsulatedback to summary
private final boolean encapsulated
encHeadersback to summary
private static final String[] encHeaders
encValuesback to summary
private static final String[] encValues
extraHeadersback to summary
private final Map<String, String> extraHeaders
micAlgsback to summary
private final Map<K, V> micAlgs
sigGenback to summary
private final CMSSignedDataStreamGenerator sigGen

Constructor Detail

Builderback to summary
public Builder()
Builderback to summary
public Builder(boolean encapsulated)

Method Detail

addBoundaryback to summary
private void addBoundary(StringBuffer header, String boundary)
addCertificateback to summary
public SMIMESignedWriter.Builder addCertificate(X509CertificateHolder certificate) throws CMSException
addCertificatesback to summary
public SMIMESignedWriter.Builder addCertificates(Store<T> certificates) throws CMSException
addHashHeaderback to summary
private void addHashHeader(StringBuffer header, List<E> signers)
addSignerInfoGeneratorback to summary
public SMIMESignedWriter.Builder addSignerInfoGenerator(SignerInfoGenerator signerGenerator)

Add a generator to produce the signer info required.

Parameters
signerGenerator:SignerInfoGenerator

a generator for a signer info object.

Returns:SMIMESignedWriter.Builder

the current Builder instance.

buildback to summary
public SMIMESignedWriter build(OutputStream mimeOut)
generateBoundaryback to summary
private String generateBoundary()
withHeaderback to summary
public SMIMESignedWriter.Builder withHeader(String headerName, String headerValue)

Specify a MIME header (name, value) pair for this builder. If the headerName already exists it will be overridden.

Parameters
headerName:String

name of the MIME header.

headerValue:String

value of the MIME header.

Returns:SMIMESignedWriter.Builder

the current Builder instance.

org.bouncycastle.mime.smime back to summary

private Class SMIMESignedWriter.ContentOutputStream

extends OutputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final OutputStream
private final OutputStream
private final OutputStream
private final ByteArrayOutputStream

Constructor Summary

AccessConstructor and Description
pack-priv

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(byte[]
the data.
buf
)

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.
public void
write(byte[]
the data.
buf
,
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(int
the byte.
i
)

Implements abstract java.io.OutputStream.write.

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

Field Detail

backingback to summary
private final OutputStream backing
mainback to summary
private final OutputStream main
sigBaseback to summary
private final OutputStream sigBase
sigStreamback to summary
private final ByteArrayOutputStream sigStream

Constructor Detail

ContentOutputStreamback to summary
pack-priv ContentOutputStream(OutputStream main, OutputStream backing, ByteArrayOutputStream sigStream, OutputStream sigBase)

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(byte[] buf) 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
buf:byte[]

the data.

Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(byte[] buf, 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
buf: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(int i) 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
i: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.