FileDocCategorySizeDatePackage
StreamBlockCipher.javaAPI DocAndroid 1.5 API2872Wed May 06 22:41:06 BST 2009org.bouncycastle.crypto

StreamBlockCipher

public class StreamBlockCipher extends Object implements StreamCipher
a wrapper for block ciphers with a single byte block size, so that they can be treated like stream ciphers.

Fields Summary
private BlockCipher
cipher
private byte[]
oneByte
Constructors Summary
public StreamBlockCipher(BlockCipher cipher)
basic constructor.

param
cipher the block cipher to be wrapped.
exception
IllegalArgumentException if the cipher has a block size other than one.


                               
     
         
    
        if (cipher.getBlockSize() != 1)
        {
            throw new IllegalArgumentException("block cipher block size != 1.");
        }

        this.cipher = cipher;
    
Methods Summary
public java.lang.StringgetAlgorithmName()
return the name of the algorithm we are wrapping.

return
the name of the algorithm we are wrapping.

        return cipher.getAlgorithmName();
    
public voidinit(boolean forEncryption, CipherParameters params)
initialise the underlying cipher.

param
forEncryption true if we are setting up for encryption, false otherwise.
param
params the necessary parameters for the underlying cipher to be initialised.

        cipher.init(forEncryption, params);
    
public voidprocessBytes(byte[] in, int inOff, int len, byte[] out, int outOff)
process a block of bytes from in putting the result into out.

param
in the input byte array.
param
inOff the offset into the in array where the data to be processed starts.
param
len the number of bytes to be processed.
param
out the output buffer the processed bytes go into.
param
outOff the offset into the output byte array the processed data stars at.
exception
DataLengthException if the output buffer is too small.

        if (outOff + len > out.length)
        {
            throw new DataLengthException("output buffer too small in processBytes()");
        }

        for (int i = 0; i != len; i++)
        {
                cipher.processBlock(in, inOff + i, out, outOff + i);
        }
    
public voidreset()
reset the underlying cipher. This leaves it in the same state it was at after the last init (if there was one).

        cipher.reset();
    
public bytereturnByte(byte in)
encrypt/decrypt a single byte returning the result.

param
in the byte to be processed.
return
the result of processing the input byte.

        oneByte[0] = in;

        cipher.processBlock(oneByte, 0, oneByte, 0);

        return oneByte[0];