org.logi.crypto.io
Class DecryptStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.FilterInputStream
              |
              +--org.logi.crypto.io.DecryptStream

public class DecryptStream
extends java.io.FilterInputStream

Decrypt a stream of data encrypted with a corresponding EncryptStream ojbect.

Author:
Logi Ragnarsson (logir@logi.org)
See Also:
EncryptStream, DecryptSession

Constructor Summary
DecryptStream(java.io.InputStream in, NoninterKeyExServer kex, DecryptSession dmode)
          Create a new DecryptStream.
 
Method Summary
 int available()
          Returns the number of bytes that can be read from this input stream without blocking.
 void close()
          Closes this input stream and releases any system resources associated with this stream.
 int drain()
          Drain random bytes inserted to fill a plain-text block.
 DecryptionKey getKey()
          Return the key used for decrypting this stream, or null if one has not been specified.
 boolean markSupported()
          Returns false.
 int read()
          Reads the next byte of data from this input stream.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data from this input stream into an array of bytes.
 void reKey(NoninterKeyExServer kex, boolean encrypt)
          Executes a non-interactive key-exchange protocol.
 void setKey(CipherKey key)
          Re-key the DecryptSession used by this DecryptStream.
 long skip(long n)
          Does nothing and returns 0.
 
Methods inherited from class java.io.FilterInputStream
mark, read, reset
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DecryptStream

public DecryptStream(java.io.InputStream in,
                     NoninterKeyExServer kex,
                     DecryptSession dmode)
              throws CryptoProtocolException,
                     java.io.IOException
Create a new DecryptStream. Plaintext is written to out, dmode is used for decryption and if kex is not null it will be used to generate the session key or receive i from the client. See the various key-exchange server classes for details.

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

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

getKey

public DecryptionKey getKey()
Return the key used for decrypting this stream, or null if one has not been specified.

setKey

public void setKey(CipherKey key)
            throws CryptoException
Re-key the DecryptSession used by this DecryptStream. This causes the stream to be drained.
Throws:
CryptoException - if the internal buffer in the DecryptSession is not empty.

reKey

public void reKey(NoninterKeyExServer kex,
                  boolean encrypt)
           throws java.io.IOException,
                  CryptoProtocolException
Executes a non-interactive key-exchange protocol. If encrypt is true, messages will be sent through the encrypted channel. This causes the stream to be drained.

After the protocol has been executed, the exchanged key will be used for decryption.

Throws:
java.io.IOException - if there is a low-level problem.
CryptoProtocolException - if the protocol could not execute.

read

public int read()
         throws java.io.IOException
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
Overrides:
read in class java.io.FilterInputStream

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads up to len bytes of data from this input stream into an array of bytes. This method blocks until some input is available.
Overrides:
read in class java.io.FilterInputStream

available

public int available()
              throws java.io.IOException
Returns the number of bytes that can be read from this input stream without blocking.
Overrides:
available in class java.io.FilterInputStream

skip

public long skip(long n)
          throws java.io.IOException
Does nothing and returns 0.
Overrides:
skip in class java.io.FilterInputStream

drain

public int drain()
Drain random bytes inserted to fill a plain-text block. If flush() was called at this point in creating the stream, drain() will remove the random bytes.
See Also:
EncryptStream.flush()

close

public void close()
           throws java.io.IOException
Closes this input stream and releases any system resources associated with this stream.
Overrides:
close in class java.io.FilterInputStream
Throws:
java.io.IOException - if an I/O error occurs.

markSupported

public boolean markSupported()
Returns false.
Overrides:
markSupported in class java.io.FilterInputStream


Copyright (c) 1997-2001 Logi Ragnarsson - Distributed under the GPL