public class PemOutputStream
extends java.io.FilterOutputStream
To be able to actually the stream the data being protected, this class requires two output streams, one to write the protected data to, and another to write the message header to.
| Constructor and Description |
|---|
PemOutputStream(java.security.PrivateKey signingKey,
X509Certificate verificationCertificate,
X509Certificate originatorCertificate,
PemOptions options,
java.io.OutputStream outStream,
java.io.OutputStream headerStream)
Creates a PEM message, signed with the given signing key, with the given
certificates used as those of the originator.
|
PemOutputStream(User user,
PemOptions options,
java.io.OutputStream outStream)
Create a PemOutputStream that does not write the header.
|
PemOutputStream(User user,
PemOptions options,
java.io.OutputStream outStream,
java.io.OutputStream headerStream)
Create a PemOutputStream that writes the protected data and header
to separate streams.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addRecipients(X509Certificate[] recipients)
Adds the certificates in the given array as message recipients.
|
void |
close()
Creates the message signature if applicable, and writes the header
to the header stream.
|
int |
countCRLFBytesWrittenDuringBase64Encoding()
Returns the number of CRLF bytes (carriage return '\r' and line feed '\n')
that were written to the underlying output stream during Base64 encoding
of the protected data.
|
PemHeader |
getHeader()
Returns the PEM header.
|
void |
useOAEP(boolean useOAEP)
Indicate whether or not OAEP padding should be used when encrypting
the message.
|
void |
write(byte[] b,
int off,
int len)
Writes
len bytes from the specified
byte array starting at offset off to
this output stream. |
void |
write(int b)
Writes the specified
byte to this output stream. |
public PemOutputStream(User user, PemOptions options, java.io.OutputStream outStream, java.io.OutputStream headerStream) throws ArchiveException, UserNotLoggedInException
user - the user that will encrypt and/or sign the messageoptions - the message protection optionsoutStream - the stream to write the protected data toheaderStream - the stream to write the PEM header to. This should be different from
outStreamUserNotLoggedInException - if the supplied user is not logged inArchiveException - if the parameters are incorrect, or there is an error initializing
the encryption or signing operation.public PemOutputStream(User user, PemOptions options, java.io.OutputStream outStream) throws ArchiveException, UserNotLoggedInException
getHeader()user - the user that will encrypt and/or sign the messageoptions - the message protection optionsoutStream - the stream to write the protected data toUserNotLoggedInException - if the supplied user is not logged inArchiveException - if the parameters are incorrect, or there is an error initializing
the encryption or signing operation.public PemOutputStream(java.security.PrivateKey signingKey,
X509Certificate verificationCertificate,
X509Certificate originatorCertificate,
PemOptions options,
java.io.OutputStream outStream,
java.io.OutputStream headerStream)
throws ArchiveException
signingKey - the private key to be used to sign the message. Set to null
if the message is not signed.verificationCertificate - the verification certificate corresponding to signingKey.
Set to null if the message is not signed.originatorCertificate - the encryption certificate of the message encryptor.
Set to null if the message is not encrypted.options - the message protection optionsoutStream - the stream to write the protected data toheaderStream - the stream to write the PEM header to. This should be different from
outStreamArchiveException - if the parameters are incorrect, or there is an error initializing
the encryption or signing operation.public void write(int b)
throws java.io.IOException
byte to this output stream.
write in class java.io.FilterOutputStreamb - the byte to write.java.io.IOException - if an I/O error occurs.public void write(byte[] b,
int off,
int len)
throws java.io.IOException
len bytes from the specified
byte array starting at offset off to
this output stream.
write in class java.io.FilterOutputStreamb - the data.off - the start offset in the data.len - the number of bytes to write.java.io.IOException - if an I/O error occurs.public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.FilterOutputStreamjava.io.IOException - if an I/O error occurs.public void addRecipients(X509Certificate[] recipients)
The certificates are checked to make sure the key usage is appropriate for encryption, but other than that no validity checks are performed. Certificates that are not appropriate for encryption are ignored.
recipients - the recipients to encrypt the message forpublic PemHeader getHeader()
close(), or the signature value will not
be correct.public void useOAEP(boolean useOAEP)
useOAEP - whether or not OAEP padding should be usedpublic int countCRLFBytesWrittenDuringBase64Encoding()
This only applys when the data is being Base64 encoded; when Base64 encoding is not used, this API returns 0.
For example, if one CRLF was written, this API will return 2 (each CRLF consists of two bytes). The CRLF byte count is required during Entrust Archive file creation; the Archive format contains a component representing the total content bytes excluding and CRLF bytes.