public class PemInputStream
extends java.io.FilterInputStream
The PEM format accepted by this class is not fully compatible with PEM protection as specified by RFC 1421. It is compatible with the PEM format output by Entrust's C++ toolkits, with the exception that it does not support the "minimal header" format.
Note: this class does not perform certificate validation when reading a message. This validation must be performed by callers.
PemOutputStream| Constructor and Description |
|---|
PemInputStream(java.io.InputStream dataStream,
boolean base64Encoded,
java.io.InputStream headerStream,
int headerLength)
Constructor for PemInputStream.
|
PemInputStream(KeyAndCertificateSource keyAndCertificateSource,
java.io.InputStream dataStream,
boolean isBase64Encoded,
java.io.InputStream headerStream,
int headerLength)
Constructor for PemInputStream.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Returns 1 if at least one byte can be read from this input
stream without blocking.
|
void |
close()
This method closes the data stream, and verifies the message
signature, if necessary.
|
PemParsedHeader |
getHeader()
Return the header parsed from the message.
|
java.security.SignatureException |
getSignatureException()
Return any exception that may have occurred when validating the
signature.
|
boolean |
isSignatureValid()
Return whether or not the signature on the data is valid.
|
void |
mark(int readlimit)
Inherited from FilterInputStream.
|
boolean |
markSupported()
This method is inherited from FilterInputStream and always returns false.
|
int |
read()
Reads and unprotects the next byte of data from the data stream,
returning the original plaintext value.
|
int |
read(byte[] b,
int off,
int len)
Reads and unprotects up to
len bytes of data from this
input stream into an array of bytes. |
void |
reset()
reset() is not supported. |
void |
setDecryptionKey(java.security.PrivateKey decryptionKey,
java.lang.String keyId)
Set the decryption key and its key id to be used to decrypt
the message.
|
public PemInputStream(KeyAndCertificateSource keyAndCertificateSource, java.io.InputStream dataStream, boolean isBase64Encoded, java.io.InputStream headerStream, int headerLength)
read() return bytes from the data stream,
not the header stream.
By using this constructor, the message decryption key is automatically obtained from the supplied key source.
keyAndCertificateSource - the object from which the private decryption key is to be
obtained. In other words, it contains the private key of
one of the message recipients.dataStream - the stream from which the PEM-protected data is readisBase64Encoded - a flag indicating whether or not the message is Base64 encodedheaderStream - the stream from which the PEM header is read. This can be the same
stream as dataStreamheaderLength - the number of bytes to read from headerStream.public PemInputStream(java.io.InputStream dataStream,
boolean base64Encoded,
java.io.InputStream headerStream,
int headerLength)
read() return bytes from the data stream,
not the header stream.dataStream - the stream from which the PEM-protected data is readbase64Encoded - a flag indicating whether or not the message is Base64 encodedheaderStream - the stream from which the PEM header is read. This can be the same
stream as dataStreamheaderLength - the number of bytes to read from headerStream.public int read()
throws java.io.IOException
int in the range
0 to 255. If no byte is available
because the end of the stream has been reached, the value
-1 is returned. This method blocks until input data
is available, the end of the stream is detected, or an exception
is thrown.
read in class java.io.FilterInputStream-1
if the end of the stream is reached.java.io.IOException - if an I/O error occurs.public int read(byte[] b,
int off,
int len)
throws java.io.IOException
len bytes of data from this
input stream into an array of bytes. This method blocks until some input is
available.read in class java.io.FilterInputStreamb - the buffer into which the data is read.off - the start offset of the data.len - the maximum number of bytes read.-1
if there is no more data because the end of the stream has been reached.java.io.IOException - if an I/O error occurs.ArchiveException - public int available()
throws java.io.IOException
available in class java.io.FilterInputStream1 if at least one byte can be read from this input
stream without blocking. Returns 0 otherwise.java.io.IOException - if an I/O error occurspublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.FilterInputStreamjava.io.IOException - if an I/O error occurs closing the data stream.public void mark(int readlimit)
mark() or reset()mark in class java.io.FilterInputStreamreadlimit - ignoredpublic void reset()
throws java.io.IOException
reset() is not supported. This method always throws an
IOException.reset in class java.io.FilterInputStreamjava.io.IOException - alwayspublic boolean markSupported()
markSupported in class java.io.FilterInputStreamfalsepublic boolean isSignatureValid()
close() method has been called. A return value of
true after close() is called indicates
that the validation succeeded.
false will always be returned for messages that were not signed.
public java.security.SignatureException getSignatureException()
close() method has been called. A return value of
null after close() is called indicates
that the validation succeeded.
null will always be returned for messages that were not signed.
public PemParsedHeader getHeader() throws ArchiveException
ArchiveException - if this call causes the header to be parsed, and there is a
problem with the header.PemParsedHeaderpublic void setDecryptionKey(java.security.PrivateKey decryptionKey,
java.lang.String keyId)
Map returned by getHeader().getRecipientKeyInfo()
If this object was constructed by passing in a User object,
it is not necessary to call this method. If this object was constructed
without a User object and the message was encrypted, this
must be called before the first call to read() or there is no
way to decrypt the message, and an exception will be thrown.
decryptionKey - the private key to be used to decrypt the message.keyId - the key identifier for the decryption key.