is.logi.crypto.io
Class EncryptStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--java.io.FilterOutputStream
              |
              +--is.logi.crypto.io.EncryptStream

public class EncryptStream
extends java.io.FilterOutputStream

This OutputStream encrypts everything written to it using the specified CipherKey and EncryptMode. It optionally first executes a non-interactive key-exchange protocol.

Beware that depending on the EncryptMode you use, garbage may be inserted into the stream when it is flushed or closed.

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

Constructor Summary
EncryptStream(java.io.OutputStream out, NoninterKeyExClient kex, EncryptMode emode)
          Create a new EncryptStream.
 
Method Summary
 void execute(NoninterProtocolClient prot)
          Executes a non-interactive protocol.
 void flush()
          Flushes this output stream and forces any buffered output bytes to be written out to the stream.
 void write(byte[] buf, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this output stream.
 void write(int b)
          Writes the specified byte to this output stream.
 
Methods inherited from class java.io.FilterOutputStream
close, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EncryptStream

public EncryptStream(java.io.OutputStream out,
                     NoninterKeyExClient kex,
                     EncryptMode emode)
              throws ProtocolException,
                     java.io.IOException
Create a new EncryptStream. Ciphertext is written to out, emode is used for encryption and if kex is not null it will be used to generate a session key and/or send it to the server. See the various key-exchange client classes for details.

Note that if kex is not null, it controls which session key is used and emode receives the session key when it has been decided. If kex is null, then emode must be initialized with a key, and the same symmetric key or matching asymmetric key must be used on the server.

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

execute

public void execute(NoninterProtocolClient prot)
             throws java.io.IOException,
                    ProtocolException
Executes a non-interactive protocol.
Throws:
ProtocolException - if there is a problem with the protocol.
java.io.IOException - if there is a problem with the underlying streams.

write

public void write(int b)
           throws java.io.IOException
Writes the specified byte to this output stream.
Overrides:
write in class java.io.FilterOutputStream

write

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

flush

public void flush()
           throws java.io.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 java.io.FilterOutputStream


Copyright 1997-1999 Logi Ragnarsson