All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class Acme.Crypto.EncryptedOutputStream

java.lang.Object
   |
   +----java.io.OutputStream
           |
           +----java.io.FilterOutputStream
                   |
                   +----Acme.Crypto.EncryptedOutputStream

public class EncryptedOutputStream
extends FilterOutputStream
An OutputStream that supports encryption.

This class encapsulates a StreamCipher or BlockCipher as an OutputStream. You set up your cipher, pass it and the underlying stream to the EncryptedOutputStream constructor, and then write your cleartext to this stream. It gets encrypted and sent to the underlying stream. Decryption is done by an EncryptedInputStream.

When used with a StreamCipher, no output protocol is necessary, each byte of cleartext turns into one byte of ciphertext. 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 cleartext is encrypted into a block of ciphertext, sent to the stream, and then one more byte is sent 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:
EncryptedInputStream, StreamCipher, BlockCipher, CbcBlockCipher

Constructor Index

 o EncryptedOutputStream(BlockCipher, OutputStream)
Constructor for block ciphers.
 o EncryptedOutputStream(StreamCipher, OutputStream)
Constructor for stream ciphers.

Method Index

 o flush()
Flush the stream.
 o setEncrypting(boolean)
Encrypting can be enabled or disabled temporarily.
 o setKey(String)
Set the key.
 o write(byte[], int, int)
Write some bytes.
 o write(int)
Write a byte.

Constructors

 o EncryptedOutputStream
 public EncryptedOutputStream(BlockCipher blockCipher,
                              OutputStream out) throws IOException
Constructor for block ciphers.

Parameters:
blockCipher - The cipher to use, e.g. DesCipher, IdeaCipher
out - The raw output stream that we will be encrypting to.
 o EncryptedOutputStream
 public EncryptedOutputStream(StreamCipher streamCipher,
                              OutputStream out)
Constructor for stream ciphers.

Parameters:
streamCipher - The cipher to use, e.g. Rc4Cipher, Rot13Cipher
out - The raw output stream that we will be encrypting to.

Methods

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

 o setEncrypting
 public void setEncrypting(boolean encrypting) throws IOException
Encrypting can be enabled or disabled temporarily.

 o write
 public void write(int b) throws IOException
Write a byte.

Overrides:
write in class FilterOutputStream
 o write
 public void write(byte b[],
                   int off,
                   int len) throws IOException
Write some bytes.

Overrides:
write in class FilterOutputStream
 o flush
 public void flush() throws IOException
Flush the stream. This will write any buffered output bytes.

Overrides:
flush in class FilterOutputStream

All Packages  Class Hierarchy  This Package  Previous  Next  Index

ACME Java  ACME Labs