public class CipherInputStream
extends com.joshvm.java.io.FilterInputStream
For example, if the Cipher is initialized for decryption, the CipherInputStream will attempt to read in data and decrypt them, before returning the decrypted data.
Constructor and Description |
---|
CipherInputStream(InputStream is,
AEADBlockCipher cipher)
Constructs a CipherInputStream from an InputStream and an AEADBlockCipher.
|
CipherInputStream(InputStream is,
AEADBlockCipher cipher,
int bufSize)
Constructs a CipherInputStream from an InputStream, an AEADBlockCipher, and a specified internal buffer size.
|
CipherInputStream(InputStream is,
BufferedBlockCipher cipher)
Constructs a CipherInputStream from an InputStream and a
BufferedBlockCipher.
|
CipherInputStream(InputStream is,
BufferedBlockCipher cipher,
int bufSize)
Constructs a CipherInputStream from an InputStream, a
BufferedBlockCipher, and a specified internal buffer size.
|
CipherInputStream(InputStream is,
StreamCipher cipher)
Constructs a CipherInputStream from an InputStream and a StreamCipher.
|
CipherInputStream(InputStream is,
StreamCipher cipher,
int bufSize)
Constructs a CipherInputStream from an InputStream, a StreamCipher, and a specified internal buffer size.
|
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns the number of bytes that can be read (or skipped over) from
this input stream without blocking by the next caller of a method for
this input stream.
|
void |
close()
Closes the underlying input stream and finalises the processing of the data by the cipher.
|
void |
mark(int readlimit)
Mark the current position.
|
boolean |
markSupported()
Return true if mark(readlimit) is supported.
|
int |
read()
Reads data from the underlying stream and processes it with the cipher until the cipher
outputs data, and returns the next available byte.
|
int |
read(byte[] b)
Reads data from the underlying stream and processes it with the cipher until the cipher
outputs data, and then returns up to
b.length bytes in the provided array. |
int |
read(byte[] b,
int off,
int len)
Reads data from the underlying stream and processes it with the cipher until the cipher
outputs data, and then returns up to
len bytes in the provided array. |
void |
reset()
Reset to the last marked position, if supported.
|
long |
skip(long n)
Skips over and discards
n bytes of data from this input
stream. |
public CipherInputStream(InputStream is, BufferedBlockCipher cipher)
public CipherInputStream(InputStream is, StreamCipher cipher)
public CipherInputStream(InputStream is, AEADBlockCipher cipher)
public CipherInputStream(InputStream is, BufferedBlockCipher cipher, int bufSize)
public CipherInputStream(InputStream is, StreamCipher cipher, int bufSize)
public CipherInputStream(InputStream is, AEADBlockCipher cipher, int bufSize)
public int read() throws IOException
If the underlying stream is exhausted by this call, the cipher will be finalised.
read
in class com.joshvm.java.io.FilterInputStream
-1
if the end of the
stream is reached.IOException
- if there was an error closing the input stream.InvalidCipherTextIOException
- if the data read from the stream was invalid ciphertext
(e.g. the cipher is an AEAD cipher and the ciphertext tag check fails).public int read(byte[] b) throws IOException
b.length
bytes in the provided array.
If the underlying stream is exhausted by this call, the cipher will be finalised.
read
in class com.joshvm.java.io.FilterInputStream
b
- the buffer into which the data is read.-1
if there is no
more data because the end of the stream has been reached.IOException
- if there was an error closing the input stream.InvalidCipherTextIOException
- if the data read from the stream was invalid ciphertext
(e.g. the cipher is an AEAD cipher and the ciphertext tag check fails).InputStream.read(byte[], int, int)
public int read(byte[] b, int off, int len) throws IOException
len
bytes in the provided array.
If the underlying stream is exhausted by this call, the cipher will be finalised.
read
in class com.joshvm.java.io.FilterInputStream
b
- the buffer into which the data is read.off
- the start offset in the destination array b
len
- the maximum number of bytes read.-1
if there is no
more data because the end of the stream has been reached.IOException
- if there was an error closing the input stream.InvalidCipherTextIOException
- if the data read from the stream was invalid ciphertext
(e.g. the cipher is an AEAD cipher and the ciphertext tag check fails).InputStream.read()
public long skip(long n) throws IOException
InputStream
n
bytes of data from this input
stream. The skip
method may, for a variety of reasons, end
up skipping over some smaller number of bytes, possibly 0
.
This may result from any of a number of conditions; reaching end of file
before n
bytes have been skipped is only one possibility.
The actual number of bytes skipped is returned. If n
is
negative, no bytes are skipped.
The skip
method of InputStream
creates a
byte array and then repeatedly reads into it until n
bytes
have been read or the end of the stream has been reached. Subclasses are
encouraged to provide a more efficient implementation of this method.
skip
in class com.joshvm.java.io.FilterInputStream
n
- the number of bytes to be skipped.IOException
- if an I/O error occurs.public int available() throws IOException
InputStream
The available
method for class InputStream
always returns 0
.
This method should be overridden by subclasses.
available
in class com.joshvm.java.io.FilterInputStream
IOException
- if an I/O error occurs.public void close() throws IOException
close
in class com.joshvm.java.io.FilterInputStream
IOException
- if there was an error closing the input stream.InvalidCipherTextIOException
- if the data read from the stream was invalid ciphertext
(e.g. the cipher is an AEAD cipher and the ciphertext tag check fails).public void mark(int readlimit)
This method only works if markSupported() returns true - which means the underlying stream supports marking, and the cipher passed in to this stream's constructor is a SkippingCipher (so capable of being reset to an arbitrary point easily).
mark
in class com.joshvm.java.io.FilterInputStream
readlimit
- the maximum read ahead required before a reset() may be called.InputStream.reset()
public void reset() throws IOException
reset
in class com.joshvm.java.io.FilterInputStream
IOException
- if marking not supported by the cipher used, or the underlying stream.InputStream.mark(int)
,
IOException
public boolean markSupported()
markSupported
in class com.joshvm.java.io.FilterInputStream
InputStream.mark(int)
,
InputStream.reset()