All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class IS.hi.logir.cryptonite.EncryptStream

java.lang.Object
   |
   +----java.io.OutputStream
           |
           +----java.io.FilterOutputStream
                   |
                   +----IS.hi.logir.cryptonite.EncryptStream

public final class EncryptStream
extends FilterOutputStream
This class is a FilterOutputStream that encrypts everything passing through it. The format of the encrypted stream is as follows:
encrypted stream = <key identifier>[block [... [block] ...]]
block = <key identifier | session key | encrypted block>
key identifier = <0x00000000><MD5 fingerprint>
session key = <negative length of block><serialized and encrypted Key object>
key-class name length = 32-bit integer
key-class name = string
cipher block = <decrypted size><cipher chunk>[cipher chunk[... [cipher chunk]... ]]

The definition of key depends on the particular key class.

The definition of cipher chunk and a more detailed explanation of cipher block is shown in the documantation of the class Key.

The last key identifier before a session key block identifies the key used to encrypt the session key.

The last session key before a cipher block contains the key used to decrypt that block. If no session key block has appeared, then the key from the last key identifier block should be used in stead.

Author:
Logi Ragnarsson (logir@hi.is)
See Also:
Key, DecryptStream

Variable Index

 o buf
 o bufSize
 o idealBufSize
 o key
 o sKey

Constructor Index

 o EncryptStream(OutputStream, Key)
Create a new stream which encrypts data written to it and writes it to out.
 o EncryptStream(OutputStream, Key, int)
Create a new stream which encrypts data written to it and writes it to out.

Method Index

 o close()
Closes this output stream and releases any system resources associated with the stream.
 o flush()
Flushes this output stream and forces any buffered output bytes to be encrypted and written.
 o init(int, Key)
 o resizeBuffer()
 o setKey(Key)
Sets the key to use for encrypting data.
 o setSessionKey(Key)
Set the session key to use for this stream.
 o write(byte[])
Encrypts and writes b.length bytes to the stream.
 o write(byte[], int, int)
Encrypts and writes len bytes from the specified byte array starting at offset off to this output stream.
 o write(int)
Encrypt and write the specified byte to the stream.
 o writeBuffer()
 o writeKey()

Variables

 o key
 private Key key
 o sKey
 private Key sKey
 o buf
 private Data buf
 o bufSize
 private int bufSize
 o idealBufSize
 private int idealBufSize

Constructors

 o EncryptStream
 public EncryptStream(OutputStream out,
                      Key key,
                      int idealBufSize) throws IOException
Create a new stream which encrypts data written to it and writes it to out. The specified key is used to encrypt the data in blocks of up to most idealBufSize bytes.

 o EncryptStream
 public EncryptStream(OutputStream out,
                      Key key) throws IOException
Create a new stream which encrypts data written to it and writes it to out. The specified key is used to encrypt the data in blocks of up to 2KB.

Methods

 o init
 private void init(int bufSize,
                   Key key) throws IOException
 o close
 public synchronized void close() throws IOException
Closes this output stream and releases any system resources associated with the stream.

Overrides:
close in class FilterOutputStream
 o writeBuffer
 private synchronized void writeBuffer() throws IOException
 o flush
 public synchronized void flush() throws IOException
Flushes this output stream and forces any buffered output bytes to be encrypted and written.

Overrides:
flush in class FilterOutputStream
 o write
 public synchronized void write(byte b[]) throws IOException
Encrypts and writes b.length bytes to the stream.

Overrides:
write in class FilterOutputStream
 o write
 public synchronized void write(byte b[],
                                int off,
                                int len) throws IOException
Encrypts and writes len bytes from the specified byte array starting at offset off to this output stream.

Overrides:
write in class FilterOutputStream
 o write
 public synchronized void write(int b) throws IOException
Encrypt and write the specified byte to the stream.

Overrides:
write in class FilterOutputStream
 o resizeBuffer
 private void resizeBuffer() throws IOException
 o setKey
 public synchronized void setKey(Key key) throws IOException
Sets the key to use for encrypting data. If a key identifier block has previously been written, another one will be written to reflect the change.

 o writeKey
 private synchronized void writeKey() throws IOException
 o setSessionKey
 public synchronized void setSessionKey(Key sk) throws IOException
Set the session key to use for this stream. Session keys can be use symmetric ciphers, which tend to be much faster than the public key ciphers used in the constructor. The session key will be encrypted with the public key and written to the stream.


All Packages  Class Hierarchy  This Package  Previous  Next  Index