All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object
|
+----java.io.InputStream
|
+----java.io.FilterInputStream
|
+----java.security.CipherInputStream
This is NOT the implementation from Sun. This class has been developed by IAIK according to the documentation publically available. Only the documentation from Sun has been inserted into the source files.
A FilterInputStream that encrypts or decrypts the data passing through it. Typically, this stream would be used as a filter to read an encrypted file.
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.
ENCRYPT or
DECRYPT.
b array with the
next len encrypted or decrypted bytes
(depending on the cipher state).
public CipherInputStream(InputStream is,
Cipher cipher)
ENCRYPT or
DECRYPT.
public CipherInputStream(InputStream is,
Cipher cipher,
int factor)
ENCRYPT or
DECRYPT.
Use this constructor to create a CipherInputStream where the internal buffer
is several times the blocksize of the cipher.
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