bufferedasymmetricblockcipher.java

来自「java 文件下载器。可自定义」· Java 代码 · 共 102 行

JAVA
102
字号
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   BufferedAsymmetricBlockCipher.java

package org.bouncycastle.crypto;


// Referenced classes of package org.bouncycastle.crypto:
//			AsymmetricBlockCipher, DataLengthException, InvalidCipherTextException, CipherParameters

public class BufferedAsymmetricBlockCipher
{

	protected byte buf[];
	protected int bufOff;
	private boolean forEncryption;
	private AsymmetricBlockCipher cipher;

	public BufferedAsymmetricBlockCipher(AsymmetricBlockCipher cipher)
	{
		this.cipher = cipher;
	}

	public AsymmetricBlockCipher getUnderlyingCipher()
	{
		return cipher;
	}

	public int getBufferPosition()
	{
		return bufOff;
	}

	public void init(boolean forEncryption, CipherParameters params)
	{
		this.forEncryption = forEncryption;
		reset();
		cipher.init(forEncryption, params);
		buf = new byte[cipher.getInputBlockSize()];
		bufOff = 0;
	}

	public int getInputBlockSize()
	{
		return cipher.getInputBlockSize();
	}

	public int getOutputBlockSize()
	{
		return cipher.getOutputBlockSize();
	}

	public void processByte(byte in)
	{
		if (bufOff > buf.length)
		{
			throw new DataLengthException("attempt to process message to long for cipher");
		} else
		{
			buf[bufOff++] = in;
			return;
		}
	}

	public void processBytes(byte in[], int inOff, int len)
	{
		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");
		} else
		{
			System.arraycopy(in, inOff, buf, bufOff, len);
			bufOff += len;
			return;
		}
	}

	public byte[] doFinal()
		throws InvalidCipherTextException
	{
		byte out[] = cipher.processBlock(buf, 0, bufOff);
		reset();
		return out;
	}

	public void reset()
	{
		if (buf != null)
		{
			for (int i = 0; i < buf.length; i++)
				buf[0] = 0;

		}
		bufOff = 0;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?