All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class Acme.Crypto.EncryptedInputStream

java.lang.Object
   |
   +----java.io.InputStream
           |
           +----java.io.FilterInputStream
                   |
                   +----Acme.Crypto.EncryptedInputStream

public class EncryptedInputStream
extends FilterInputStream
An InputStream that supports encryption.

This class encapsulates a StreamCipher or BlockCipher as an InputStream. You set up your cipher, pass it and the underlying stream to the EncryptedInputStream constructor, and then read your cleartext from this stream. It gets read from the underlying stream and decrypted. Encryption is done by an EncryptedOutputStream.

When used with a StreamCipher, no input protocol is necessary, each byte of ciphertext turns into one byte of cleartext. When used with a BlockCipher it's more complicated. First, the raw BlockCipher gets encapsulated into a CbcBlockCipher, which needs an initialization vector; so each encrypted stream automatically starts off with such a vector. After that, the stream is a series of (block,bytecount) pairs. Each block of ciphertext is read from the stream, decrypted into a block of cleartext, and then one more byte is read that says how many bytes in the block are valid. Generally the bytecount will be equal to the block size, but it can be less if the stream gets flushed or closed on a partial block.

Fetch the software.
Fetch the entire Acme package.

See Also:
EncryptedOutputStream, StreamCipher, BlockCipher, CbcBlockCipher

Constructor Index

 o EncryptedInputStream(BlockCipher, InputStream)
Constructor for block ciphers.
 o EncryptedInputStream(StreamCipher, InputStream)
Constructor for stream ciphers.

Method Index

 o read()
Read a byte of data.
 o read(byte[], int, int)
Read into an array of bytes.
 o setDecrypting(boolean)
Decrypting can be enabled or disabled temporarily.
 o setKey(String)
Set the key.

Constructors

 o EncryptedInputStream
 public EncryptedInputStream(BlockCipher blockCipher,
                             InputStream in)
Constructor for block ciphers.

Parameters:
blockCipher - The cipher to use, e.g. DesCipher, IdeaCipher
in - The raw input stream that we will be decrypting.
 o EncryptedInputStream
 public EncryptedInputStream(StreamCipher streamCipher,
                             InputStream in)
Constructor for stream ciphers.

Parameters:
streamCipher - The cipher to use, e.g. Rc4Cipher, Rot13Cipher
in - The raw input stream that we will be decrypting.

Methods

 o setKey
 public void setKey(String keyStr)
Set the key.

 o setDecrypting
 public void setDecrypting(boolean decrypting) throws IOException
Decrypting can be enabled or disabled temporarily.

 o read
 public int read() throws IOException
Read a byte of data.

Returns:
-1 on EOF.
Overrides:
read in class FilterInputStream
 o read
 public int read(byte b[],
                 int off,
                 int len) throws IOException
Read into an array of bytes. This is a fixed version of java.io.InputStream.read(byte[], int, int). The standard version catches and ignores IOExceptions from below; this version sends them on to the caller.

Overrides:
read in class FilterInputStream

All Packages  Class Hierarchy  This Package  Previous  Next  Index

ACME Java  ACME Labs