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 an input stream and a Cipher as arguments. The cipher is used to encrypt or decrypt all data read through the stream.
The data is encrypted or decrypted, depending on the initialisation
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 block ciphers, some buffering of the data received from the input stream is done. The buffer length is calculated as follows:
buffer length = cipher.getInputBlockSize() +
(cipher.isPaddingBlockCipher() &&
cipher.getState() == Cipher.DECRYPT) ? 1 : 0
Each read operation will attempt to completely fill the buffer. The maximum
number of bytes that can remain unprocessed after each read call
is one less than the buffer length. In the case of a padding block cipher in
DECRYPT mode, this means that one full ciphertext block may remain
unprocessed, because it is necessary to read an extra byte in order to
determine whether this is the last block of the stream. (It would be
incorrect to process a block without making this check, since it may have
padding bytes that need to be stripped out.)
When EOF is reached for a padding/unpadding cipher in DECRYPT mode, the the decryption result is unpadded. If EOF is encountered part-way through a block, an IllegalBlockSizeException is thrown.
When EOF is reached for a padding/unpadding cipher in ENCRYPT mode, the last block is padded before encryption. If the cipher does not support padding and the last block is incomplete, an IllegalBlockSizeException is thrown.
For stream ciphers, that is, ciphers capable of encrypting or decrypting a byte at a time, no buffering is necessary.
Note: calling methods of a cipher while it is being used by a
CipherInputStream (apart from methods that have no side-effects,
like getAlgorithm(), get*BlockSize(), etc.)
will probably result in incorrect or unexpected output.
Copyright © 1997
Systemics Ltd on behalf of the
Cryptix Development Team.
All rights reserved.
$Revision: 1.9 $
ENCRYPT or
DECRYPT.
mark and
reset methods of InputStream, which it does not.
public CipherInputStream(InputStream is,
Cipher cipher)
ENCRYPT or
DECRYPT.
public synchronized int read(byte out[],
int offset,
int length) throws IOException
public synchronized int read() throws IOException
public synchronized long skip(long n) throws IOException
skip method may, for a variety of
reasons, end up skipping over some smaller number of bytes,
possibly 0. The actual number of bytes skipped is returned.
public synchronized int available() throws IOException
public synchronized void close() throws IOException
public void mark(int readlimit)
public void reset() throws IOException
public boolean markSupported()
mark and
reset methods of InputStream, which it does not.
false, since this class does not support the
mark and reset methods.
All Packages Class Hierarchy This Package Previous Next Index