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.
This is a reimplementation of javax. that is safe for use with
AEAD block ciphers, and does not silently catch BadPaddingException and
IllegalBlockSizeException errors. Any errors that occur during finalisation are rethrown wrapped in an InvalidCipherTextIOException.
| Modifier and Type | Field and Description |
|---|---|
| private byte[] | |
| private int | |
| private final Cipher | |
| private boolean | |
| private final byte[] | |
| private int |
| Access | Constructor and Description |
|---|---|
| public | CipherInputStream(InputStream input, Cipher cipher)
Constructs a CipherInputStream from an InputStream and an initialised Cipher. |
| Modifier and Type | Method and Description |
|---|---|
| public int | available()
Overrides java. |
| public void | close()
Overrides java. Implements java. |
| private byte[] | |
| public void | mark(int
the maximum limit of bytes that can be read before
the mark position becomes invalid. readlimit)Overrides java. |
| public boolean | markSupported()
Overrides java. mark
and reset methods.
|
| private int | Returns: -1 to indicate end of stream, or the number of bytes (> 0) available.Read data from underlying stream and process with cipher until end of stream or some data is available after cipher processing. |
| public int | read()
Overrides java. |
| public int | Returns: the total number of bytes read into the buffer, or-1 if there is no
more data because the end of the stream has been reached.the buffer into which the data is read. b, int the start offset in the destination array off, int bthe maximum number of bytes read. len)Overrides java. len bytes in the provided array.
|
| public void | reset()
Overrides java. mark method was last called on this input stream.
|
| public long | skip(long
the number of bytes to be skipped. n)Overrides java. n bytes of data from the
input stream.
|
| buf | back to summary |
|---|---|
| private byte[] buf | |
| bufOff | back to summary |
|---|---|
| private int bufOff | |
| cipher | back to summary |
|---|---|
| private final Cipher cipher | |
| finalized | back to summary |
|---|---|
| private boolean finalized | |
| inputBuffer | back to summary |
|---|---|
| private final byte[] inputBuffer | |
| maxBuf | back to summary |
|---|---|
| private int maxBuf | |
| CipherInputStream | back to summary |
|---|---|
| public CipherInputStream(InputStream input, Cipher cipher) Constructs a CipherInputStream from an InputStream and an initialised Cipher. | |
| available | back to summary |
|---|---|
| public int available() throws IOException Overrides java. Doc from java. Returns an estimate of 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. The next caller might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Closes the underlying input stream, and then finalises the processing of the data by the cipher.
| |
| finaliseCipher | back to summary |
|---|---|
| private byte[] finaliseCipher() throws InvalidCipherTextIOException | |
| mark | back to summary |
|---|---|
| public void mark(int readlimit) Overrides java. Doc from java. Marks the current position in this input stream. A subsequent
call to the
The
| |
| markSupported | back to summary |
|---|---|
| public boolean markSupported() Overrides java. Doc from java. Tests if this input stream supports the
| |
| nextChunk | back to summary |
|---|---|
| private int nextChunk() throws IOException Read data from underlying stream and process with cipher until end of stream or some data is available after cipher processing.
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Overrides java. Reads data from the underlying stream and processes it with the cipher until the cipher outputs data, and returns the next available byte. If the underlying stream is exhausted by this call, the cipher will be finalised.
| |
| read | back to summary |
|---|---|
| public int read(byte[] b, int off, int len) throws IOException Overrides java. Reads data from the underlying stream and processes it with the cipher until the cipher
outputs data, and then returns up to If the underlying stream is exhausted by this call, the cipher will be finalised.
| |
| reset | back to summary |
|---|---|
| public void reset() throws IOException Overrides java. Doc from java. Repositions this stream to the position at the time the
Stream marks are intended to be used in situations where you need to read ahead a little to see what's in the stream. Often this is most easily done by invoking some general parser. If the stream is of the type handled by the parse, it just chugs along happily. If the stream is not of that type, the parser should toss an exception when it fails. If this happens within readlimit bytes, it allows the outer code to reset the stream and try another parser.
| |
| skip | back to summary |
|---|---|
| public long skip(long n) throws IOException Overrides java. Doc from java. Skips over and discards
| |