@ThreadSafety(level=NOT_THREADSAFE) public final class PassphraseEncryptedInputStream extends java.io.InputStream
InputStream
implementation that can read
encrypted data written by the PassphraseEncryptedOutputStream
. It
will use a provided password in conjunction with a
PassphraseEncryptedStreamHeader
that will either be read from the
beginning of the stream or provided in the constructor.Constructor and Description |
---|
PassphraseEncryptedInputStream(char[] passphrase,
java.io.InputStream wrappedInputStream)
Creates a new passphrase-encrypted input stream that will read the
PassphraseEncryptedStreamHeader from the underlying input stream. |
PassphraseEncryptedInputStream(java.io.InputStream wrappedInputStream,
PassphraseEncryptedStreamHeader encryptionHeader)
Creates a new passphrase-encrypted input stream using the provided
information.
|
PassphraseEncryptedInputStream(java.lang.String passphrase,
java.io.InputStream wrappedInputStream)
Creates a new passphrase-encrypted input stream that will read the
PassphraseEncryptedStreamHeader from the underlying input stream. |
Modifier and Type | Method and Description |
---|---|
int |
available()
Retrieves an estimate of the number of decrypted byte that are available to
read from the underlying stream without blocking.
|
void |
close()
Closes this input stream and the underlying stream.
|
PassphraseEncryptedStreamHeader |
getEncryptionHeader()
Retrieves an encryption header with details about the encryption used when
the data was originally written.
|
void |
mark(int readLimit)
Marks the current position in this input stream so that the caller may
return to that spot (and re-read the data) using the
reset()
method. |
boolean |
markSupported()
|
int |
read()
Retrieves a single byte of decrypted data read from the underlying input
stream.
|
int |
read(byte[] b)
Reads decrypted data and writes it into the provided byte array.
|
int |
read(byte[] b,
int offset,
int length)
Reads decrypted data and writes it into the specified portion of the
provided byte array.
|
void |
reset()
Attempts to reset the position of this input stream to the position of the
last call to
mark(int) . |
long |
skip(long maxBytesToSkip)
Skips over and discards up to the specified number of bytes of decrypted
data obtained from the underlying input stream.
|
public PassphraseEncryptedInputStream(@NotNull java.lang.String passphrase, @NotNull java.io.InputStream wrappedInputStream) throws java.io.IOException, LDAPException, java.security.InvalidKeyException, java.security.GeneralSecurityException
PassphraseEncryptedStreamHeader
from the underlying input stream.passphrase
- The passphrase used to generate the encryption
key when the corresponding
PassphraseEncryptedOutputStream
was
created.wrappedInputStream
- The input stream from which the encryption
header and encrypted data will be read.java.io.IOException
- If a problem is encountered while trying to read the
encryption header from the provided input stream.LDAPException
- If s problem is encountered while trying to parse
the encryption header read from the provided input
stream.java.security.InvalidKeyException
- If the MAC contained in the header does not
match the expected value.java.security.GeneralSecurityException
- If a problem occurs while attempting to
initialize the decryption.public PassphraseEncryptedInputStream(@NotNull char[] passphrase, @NotNull java.io.InputStream wrappedInputStream) throws java.io.IOException, LDAPException, java.security.InvalidKeyException, java.security.GeneralSecurityException
PassphraseEncryptedStreamHeader
from the underlying input stream.passphrase
- The passphrase used to generate the encryption
key when the corresponding
PassphraseEncryptedOutputStream
was
created.wrappedInputStream
- The input stream from which the encryption
header and encrypted data will be read.java.io.IOException
- If a problem is encountered while trying to read the
encryption header from the provided input stream.LDAPException
- If s problem is encountered while trying to parse
the encryption header read from the provided input
stream.java.security.InvalidKeyException
- If the MAC contained in the header does not
match the expected value.java.security.GeneralSecurityException
- If a problem occurs while attempting to
initialize the decryption.public PassphraseEncryptedInputStream(@NotNull java.io.InputStream wrappedInputStream, @NotNull PassphraseEncryptedStreamHeader encryptionHeader) throws java.security.GeneralSecurityException
wrappedInputStream
- The input stream from which the encrypted data
will be read.encryptionHeader
- The encryption header with the information
needed (in conjunction with the given
passphrase) to decrypt the data read from the
provided input stream.java.security.GeneralSecurityException
- If a problem occurs while attempting to
initialize the decryption.public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
- If a problem is encountered while reading or
decrypting the data.public int read(@NotNull byte[] b) throws java.io.IOException
read
in class java.io.InputStream
b
- The byte array into which the decrypted data will be placed,
starting with an index of zero. It must not be null
or
empty.java.io.IOException
- If a problem is encountered while reading or
decrypting the data.public int read(@NotNull byte[] b, int offset, int length) throws java.io.IOException
read
in class java.io.InputStream
b
- The byte array into which the decrypted data will be
placed. It must not be null
or empty.offset
- The position in the provided array at which to begin adding
the decrypted data. It must be greater than or equal to
zero and less than the length of the provided array.length
- The maximum number of bytes to be added to the given array.
This must be greater than zero, and the sum of the
offset
and length
must be less than or
equal to the length of the provided array.java.io.IOException
- If a problem is encountered while reading or
decrypting the data.public long skip(long maxBytesToSkip) throws java.io.IOException
skip
in class java.io.InputStream
maxBytesToSkip
- The maximum number of bytes to skip.java.io.IOException
- If a problem is encountered while skipping data from
the stream.public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
- If a problem is encountered while attempting to
determine the number of bytes available to read.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
- If a problem is encountered while closing the stream.public boolean markSupported()
markSupported
in class java.io.InputStream
true
if this input stream supports the mark
and
reset
methods, or false
if not.public void mark(int readLimit)
reset()
method. Use the markSupported()
method to determine whether this
feature is supported for this input stream.mark
in class java.io.InputStream
readLimit
- The maximum number of bytes expected to be read between
the mark and the call to the reset
method.public void reset() throws java.io.IOException
mark(int)
. Use the markSupported()
method
to determine whether this feature is supported for ths input stream.reset
in class java.io.InputStream
java.io.IOException
- If a problem is encountered while performing the
reset (e.g., no mark has been set, if too much data
has been read since setting the mark, or if the
mark
and reset
methods are not
supported).@NotNull public PassphraseEncryptedStreamHeader getEncryptionHeader()