public class CipherInputStream extends 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.
This is a reimplementation of CipherInputStream 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.
in| Constructor and Description |
|---|
CipherInputStream(InputStream input,
Cipher cipher)
Constructs a CipherInputStream from an InputStream and an initialised Cipher.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
close()
Closes the underlying input stream, and then finalises the processing of the data by the
cipher.
|
void |
mark(int readlimit) |
boolean |
markSupported() |
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,
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() |
long |
skip(long n) |
readpublic CipherInputStream(InputStream input, Cipher cipher)
public int read()
throws IOException
If the underlying stream is exhausted by this call, the cipher will be finalised.
read in class FilterInputStreamIOException - 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,
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 FilterInputStreamb - the buffer into which the data is read.off - the start offset in the destination array blen - 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).public long skip(long n)
throws IOException
skip in class FilterInputStreamIOExceptionpublic int available()
throws IOException
available in class FilterInputStreamIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class FilterInputStreamIOException - 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)
mark in class FilterInputStreampublic void reset()
throws IOException
reset in class FilterInputStreamIOExceptionpublic boolean markSupported()
markSupported in class FilterInputStreamCopyright © 2015–2021 The veraPDF Consortium. All rights reserved.