Package org.bouncycastle.jcajce.io
Class CipherInputStream
- java.lang.Object
 - 
- java.io.InputStream
 - 
- java.io.FilterInputStream
 - 
- org.bouncycastle.jcajce.io.CipherInputStream
 
 
 
 
- 
- All Implemented Interfaces:
 java.io.Closeable,java.lang.AutoCloseable
public class CipherInputStream extends java.io.FilterInputStreamA CipherInputStream is composed of an InputStream and a cipher so that read() methods return data that are read in from the underlying InputStream but have been additionally processed by the Cipher. The cipher must be fully initialized before being used by a CipherInputStream.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
CipherInputStreamthat is safe for use with AEAD block ciphers, and does not silently catchBadPaddingExceptionandIllegalBlockSizeExceptionerrors. Any errors that occur duringfinalisationare rethrown wrapped in anInvalidCipherTextIOException. 
- 
- 
Constructor Summary
Constructors Constructor Description CipherInputStream(java.io.InputStream input, javax.crypto.Cipher cipher)Constructs a CipherInputStream from an InputStream and an initialised Cipher. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()Closes the underlying input stream, and then finalises the processing of the data by the cipher.voidmark(int readlimit)booleanmarkSupported()intread()Reads data from the underlying stream and processes it with the cipher until the cipher outputs data, and returns the next available byte.intread(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 tolenbytes in the provided array.voidreset()longskip(long n) 
 - 
 
- 
- 
Method Detail
- 
read
public int read() throws java.io.IOExceptionReads 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.
- Overrides:
 readin classjava.io.FilterInputStream- Throws:
 java.io.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).
 
- 
read
public int read(byte[] b, int off, int len) throws java.io.IOExceptionReads data from the underlying stream and processes it with the cipher until the cipher outputs data, and then returns up tolenbytes in the provided array.If the underlying stream is exhausted by this call, the cipher will be finalised.
- Overrides:
 readin classjava.io.FilterInputStream- Parameters:
 b- the buffer into which the data is read.off- the start offset in the destination arrayblen- the maximum number of bytes read.- Returns:
 - the total number of bytes read into the buffer, or 
-1if there is no more data because the end of the stream has been reached. - Throws:
 java.io.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).
 
- 
skip
public long skip(long n) throws java.io.IOException- Overrides:
 skipin classjava.io.FilterInputStream- Throws:
 java.io.IOException
 
- 
available
public int available() throws java.io.IOException- Overrides:
 availablein classjava.io.FilterInputStream- Throws:
 java.io.IOException
 
- 
close
public void close() throws java.io.IOExceptionCloses the underlying input stream, and then finalises the processing of the data by the cipher.- Specified by:
 closein interfacejava.lang.AutoCloseable- Specified by:
 closein interfacejava.io.Closeable- Overrides:
 closein classjava.io.FilterInputStream- Throws:
 java.io.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).
 
- 
mark
public void mark(int readlimit)
- Overrides:
 markin classjava.io.FilterInputStream
 
- 
reset
public void reset() throws java.io.IOException- Overrides:
 resetin classjava.io.FilterInputStream- Throws:
 java.io.IOException
 
- 
markSupported
public boolean markSupported()
- Overrides:
 markSupportedin classjava.io.FilterInputStream
 
 - 
 
 -