All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object
|
+----java.io.InputStream
|
+----java.io.FilterInputStream
|
+----java.security.CipherInputStream
This class has a constructor that takes a Cipher and an input stream as arguments. The cipher is used to encrypt or decrypt all data read through the stream.
For block ciphers, some buffering of the data received from the input stream is done. The buffer length is the cipher's block size. For stream ciphers, that is, ciphers capable of encrypting or decrypting a byte at a time, no buffering is necessary.
The data is encrypted or decrypted, depending on the initialization
state of the Cipher. To get the encryption/decryption result bytes, make
one or more calls to the read methods. One
read method, with no arguments, returns the
next result byte. The other read
method returns multiple result bytes at once.
For a buffered decrypter stream, every time the buffer is empty, the stream attempts to read a complete buffer, and blocks until it does. When it has read a buffer, it decrypts it. If the next byte is an EOF and the cipher is a padding/unpadding cipher, the decryption result is then unpadded. If an EOF is encountered before a whole buffer has been read, an exception is thrown.
For a buffered encrypter stream, every time the buffer is empty, the stream attempts to read a complete buffer, and blocks until it does. If it reads a whole buffer without reaching EOF, it encrypts it. If it reaches EOF in the middle of a buffer, and the cipher is a padding cipher, it will pad the buffer, and encrypt it. Otherwise, an exception will be thrown.
ENCRYPT or
DECRYPT.
b array with the
next len encrypted or decrypted bytes
(depending on the cipher state).
public CipherInputStream(InputStream in,
Cipher cipher)
ENCRYPT or
DECRYPT.
public int read(byte b[],
int off,
int len) throws IOException
b array with the
next len encrypted or decrypted bytes
(depending on the cipher state).
b indicating where the
first encrypted or decrypted byte should be read.
b, starting at offset off.
b, or -1 if
fewer than len encrypted/decrypted bytes remained.
public int read() throws IOException
All Packages Class Hierarchy This Package Previous Next Index