public class CryptoInputStream extends InputStream implements ReadableByteChannel
| Modifier and Type | Field and Description |
|---|---|
static int |
EOS
The index value when the end of the stream has been reached
-1. |
static String |
STREAM_BUFFER_SIZE_KEY
The configuration key of the buffer size for stream.
|
| Modifier | Constructor and Description |
|---|---|
protected |
CryptoInputStream(Input input,
CryptoCipher cipher,
int bufferSize,
Key key,
AlgorithmParameterSpec params)
Constructs a
CryptoInputStream. |
protected |
CryptoInputStream(InputStream inputStream,
CryptoCipher cipher,
int bufferSize,
Key key,
AlgorithmParameterSpec params)
Constructs a
CryptoInputStream. |
protected |
CryptoInputStream(ReadableByteChannel channel,
CryptoCipher cipher,
int bufferSize,
Key key,
AlgorithmParameterSpec params)
Constructs a
CryptoInputStream. |
|
CryptoInputStream(String transformation,
Properties properties,
InputStream inputStream,
Key key,
AlgorithmParameterSpec params)
Constructs a
CryptoInputStream. |
|
CryptoInputStream(String transformation,
Properties properties,
ReadableByteChannel channel,
Key key,
AlgorithmParameterSpec params)
Constructs a
CryptoInputStream. |
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Overrides the
InputStream.available(). |
protected void |
checkStream()
Checks whether the stream is closed.
|
void |
close()
Overrides the
InputStream.close(). |
protected void |
decrypt()
Does the decryption using inBuffer as input and outBuffer as output.
|
protected void |
decryptFinal()
Does final of the cipher to end the decrypting stream.
|
protected int |
decryptMore()
Decrypts more data by reading the under layer stream.
|
protected void |
freeBuffers()
Forcibly free the direct buffers.
|
protected int |
getBufferSize()
Gets the buffer size.
|
protected CryptoCipher |
getCipher()
Gets the internal CryptoCipher.
|
protected Input |
getInput()
Gets the input.
|
protected Key |
getKey()
Gets the key.
|
protected AlgorithmParameterSpec |
getParams()
Gets the specification of cryptographic parameters.
|
protected void |
initCipher()
Initializes the cipher.
|
boolean |
isOpen()
Overrides the
Channel.isOpen(). |
boolean |
markSupported()
Overrides the
InputStream.markSupported(). |
int |
read()
Overrides the
InputStream.read(). |
int |
read(byte[] array,
int off,
int len)
Overrides the
InputStream.read(byte[], int, int). |
int |
read(ByteBuffer dst)
Overrides the
ReadableByteChannel.read(ByteBuffer). |
long |
skip(long n)
Overrides the
InputStream.skip(long). |
mark, read, resetpublic static final String STREAM_BUFFER_SIZE_KEY
public static final int EOS
-1.protected CryptoInputStream(Input input, CryptoCipher cipher, int bufferSize, Key key, AlgorithmParameterSpec params) throws IOException
CryptoInputStream.input - the input data.cipher - the cipher instance.bufferSize - the bufferSize.key - crypto key for the cipher.params - the algorithm parameters.IOException - if an I/O error occurs.protected CryptoInputStream(InputStream inputStream, CryptoCipher cipher, int bufferSize, Key key, AlgorithmParameterSpec params) throws IOException
CryptoInputStream.cipher - the cipher instance.inputStream - the input stream.bufferSize - the bufferSize.key - crypto key for the cipher.params - the algorithm parameters.IOException - if an I/O error occurs.protected CryptoInputStream(ReadableByteChannel channel, CryptoCipher cipher, int bufferSize, Key key, AlgorithmParameterSpec params) throws IOException
CryptoInputStream.channel - the ReadableByteChannel instance.cipher - the cipher instance.bufferSize - the bufferSize.key - crypto key for the cipher.params - the algorithm parameters.IOException - if an I/O error occurs.public CryptoInputStream(String transformation, Properties properties, InputStream inputStream, Key key, AlgorithmParameterSpec params) throws IOException
CryptoInputStream.transformation - the name of the transformation, e.g.,
AES/CBC/PKCS5Padding.
See the Java Cryptography Architecture Standard Algorithm Name Documentation
for information about standard transformation names.properties - The Properties class represents a set of
properties.inputStream - the input stream.key - crypto key for the cipher.params - the algorithm parameters.IOException - if an I/O error occurs.public CryptoInputStream(String transformation, Properties properties, ReadableByteChannel channel, Key key, AlgorithmParameterSpec params) throws IOException
CryptoInputStream.transformation - the name of the transformation, e.g.,
AES/CBC/PKCS5Padding.
See the Java Cryptography Architecture Standard Algorithm Name Documentation
for information about standard transformation names.properties - The Properties class represents a set of
properties.channel - the ReadableByteChannel object.key - crypto key for the cipher.params - the algorithm parameters.IOException - if an I/O error occurs.public int available() throws IOException
InputStream.available(). Returns an estimate of the
number of bytes that can be read (or skipped over) from this input stream
without blocking by the next invocation of a method for this input
stream.available in class InputStream0 when
it reaches the end of the input stream.IOException - if an I/O error occurs.protected void checkStream() throws IOException
IOException - if an I/O error occurs.public void close() throws IOException
InputStream.close(). Closes this input stream and
releases any system resources associated with the stream.close in interface Closeableclose in interface AutoCloseableclose in interface Channelclose in class InputStreamIOException - if an I/O error occurs.protected void decrypt() throws IOException
IOException - if an I/O error occurs.protected void decryptFinal() throws IOException
IOException - if an I/O error occurs.protected int decryptMore() throws IOException
IOException - if an I/O error occurs.protected void freeBuffers()
protected int getBufferSize()
protected CryptoCipher getCipher()
protected AlgorithmParameterSpec getParams()
protected void initCipher() throws IOException
IOException - if an I/O error occurs.public boolean isOpen()
Channel.isOpen().public boolean markSupported()
InputStream.markSupported().markSupported in class InputStreamCtrCryptoInputStream don't support the mark
method.public int read() throws IOException
InputStream.read(). Reads the next byte of
data from the input stream.read in class InputStreamEOS (-1) if the end of the
stream is reached.IOException - if an I/O error occurs.public int read(byte[] array, int off, int len) throws IOException
InputStream.read(byte[], int, int).
Decryption is buffer based. If there is data in outBuffer, then
read it out of this buffer. If there is no data in outBuffer,
then read more from the underlying stream and do the decryption.read in class InputStreamarray - the buffer into which the decrypted data is read.off - the buffer offset.len - the maximum number of decrypted data bytes to read.IOException - if an I/O error occurs.public int read(ByteBuffer dst) throws IOException
ReadableByteChannel.read(ByteBuffer). Reads a
sequence of bytes from this channel into the given buffer.read in interface ReadableByteChanneldst - The buffer into which bytes are to be transferred.EOS (-1) if the
channel has reached end-of-stream.IOException - if an I/O error occurs.public long skip(long n) throws IOException
InputStream.skip(long). Skips over and
discards n bytes of data from this input stream.skip in class InputStreamn - the number of bytes to be skipped.IOException - if an I/O error occurs.Copyright © 2016–2022 The Apache Software Foundation. All rights reserved.