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 class EncryptStream
extends FilterOutputStream
This OutputStream encrypts everything written to it using the key suggested by the key-exchange object passed to the constructor and in the mode passed to the constructor.

Beware that up to one byte less than a whole block of garbage may be appended to the data when flush is called, such as when the stream is closed.

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

Constructor Index

 o EncryptStream(OutputStream, NoninterKeyExClient, EncryptMode)
Create a new EncryptStream which writes encrypted data to out.

Method Index

 o flush()
Flushes this output stream and forces any buffered output bytes to be written out to the stream.
 o write(byte[], int, int)
Writes len bytes from the specified byte array starting at offset off to this output stream.
 o write(int)
Writes the specified byte to this output stream.

Constructors

 o EncryptStream
 public EncryptStream(OutputStream out,
                      NoninterKeyExClient kex,
                      EncryptMode emode) throws ProtocolException, IOException
Create a new EncryptStream which writes encrypted data to out. The emode object will be used for encryption and if kex is not null it will be used to inform the appropriate reader about what key to use for decryption.

if kex is not null, then the key returned by its sessionKey() method will be used in the emode object. Otherwise, emode is assumed to contain the proper key.

The data output can be read by a DecryptStream object which has been initialized with the DecryptMode object which corresponds to emode and the NoninteractiveKeyExchangeServer object which corresponds kex, or null if kex is null.

Throws: ProtocolException
if a problem arises with the key-exchange protocol.
Throws: IOException
if problems arise with the underlying OutputStream.

Methods

 o write
 public synchronized void write(int b) throws IOException
Writes the specified byte to this output stream.

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

Overrides:
write in class FilterOutputStream
 o flush
 public synchronized void flush() throws IOException
Flushes this output stream and forces any buffered output bytes to be written out to the stream. If the number of bytes written is not a multiple of the plainBlockSize of the Key used for encryption, up to one byte less than a whole block of garbage may be appended to the data when flush is called.

Overrides:
flush in class FilterOutputStream

All Packages  Class Hierarchy  This Package  Previous  Next  Index