FileDocCategorySizeDatePackage
BufferedAsymmetricBlockCipher.javaAPI DocAzureus 3.0.3.43856Tue Jun 08 05:12:58 BST 2004org.bouncycastle.crypto

BufferedAsymmetricBlockCipher

public class BufferedAsymmetricBlockCipher extends Object
a buffer wrapper for an asymmetric block cipher, allowing input to be accumulated in a piecemeal fashion until final processing.

Fields Summary
protected byte[]
buf
protected int
bufOff
private boolean
forEncryption
private AsymmetricBlockCipher
cipher
Constructors Summary
public BufferedAsymmetricBlockCipher(AsymmetricBlockCipher cipher)
base constructor.

param
cipher the cipher this buffering object wraps.

        this.cipher = cipher;
	
Methods Summary
public byte[]doFinal()
process the contents of the buffer using the underlying cipher.

return
the result of the encryption/decryption process on the buffer.
exception
InvalidCipherTextException if we are given a garbage block.

        byte[] out = cipher.processBlock(buf, 0, bufOff);

        reset();

        return out;
	
public intgetBufferPosition()
return the amount of data sitting in the buffer.

return
the amount of data sitting in the buffer.

        return bufOff;
    
public intgetInputBlockSize()
returns the largest size an input block can be.

return
maximum size for an input block.

		return cipher.getInputBlockSize();
	
public intgetOutputBlockSize()
returns the maximum size of the block produced by this cipher.

return
maximum size of the output block produced by the cipher.

		return cipher.getOutputBlockSize();
	
public AsymmetricBlockCiphergetUnderlyingCipher()
return the underlying cipher for the buffer.

return
the underlying cipher for the buffer.

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

param
forEncryption if true the cipher is initialised for encryption, if false for decryption.
param
param the key and other data required by the cipher.

        this.forEncryption = forEncryption;

        reset();

        cipher.init(forEncryption, params);

        buf = new byte[cipher.getInputBlockSize()];
        bufOff = 0;
    
public voidprocessByte(byte in)
add another byte for processing.

param
in the input byte.

        if (bufOff > buf.length)
        {
            throw new DataLengthException("attempt to process message to long for cipher");
        }

        buf[bufOff++] = in;
    
public voidprocessBytes(byte[] in, int inOff, int len)
add len bytes to the buffer for processing.

param
in the input data
param
inOff offset into the in array where the data starts
param
len the length of the block to be processed.

        if (len == 0)
        {
            return;
        }

        if (len < 0)
        {
            throw new IllegalArgumentException("Can't have a negative input length!");
        }

        if (bufOff + len > buf.length)
        {
            throw new DataLengthException("attempt to process message to long for cipher");
        }

        System.arraycopy(in, inOff, buf, bufOff, len);
        bufOff += len;
	
public voidreset()
Reset the buffer and the underlying cipher.

        /*
         * clean the buffer.
         */
        if (buf != null)
        {
            for (int i = 0; i < buf.length; i++)
            {
                buf[0] = 0;
            }
        }

        bufOff = 0;