⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbcblockcipher.java

📁 java 文件下载器。可自定义
💻 JAVA
字号:
// 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:   CBCBlockCipher.java

package org.bouncycastle.crypto.modes;

import org.bouncycastle.crypto.*;
import org.bouncycastle.crypto.params.ParametersWithIV;

public class CBCBlockCipher
	implements BlockCipher
{

	private byte IV[];
	private byte cbcV[];
	private byte cbcNextV[];
	private int blockSize;
	private BlockCipher cipher;
	private boolean encrypting;

	public CBCBlockCipher(BlockCipher cipher)
	{
		this.cipher = null;
		this.cipher = cipher;
		blockSize = cipher.getBlockSize();
		IV = new byte[blockSize];
		cbcV = new byte[blockSize];
		cbcNextV = new byte[blockSize];
	}

	public BlockCipher getUnderlyingCipher()
	{
		return cipher;
	}

	public void init(boolean encrypting, CipherParameters params)
		throws IllegalArgumentException
	{
		this.encrypting = encrypting;
		if (params instanceof ParametersWithIV)
		{
			ParametersWithIV ivParam = (ParametersWithIV)params;
			byte iv[] = ivParam.getIV();
			if (iv.length != blockSize)
				throw new IllegalArgumentException("initialisation vector must be the same length as block size");
			System.arraycopy(iv, 0, IV, 0, iv.length);
			reset();
			cipher.init(encrypting, ivParam.getParameters());
		} else
		{
			reset();
			cipher.init(encrypting, params);
		}
	}

	public String getAlgorithmName()
	{
		return (new StringBuilder()).append(cipher.getAlgorithmName()).append("/CBC").toString();
	}

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

	public int processBlock(byte in[], int inOff, byte out[], int outOff)
		throws DataLengthException, IllegalStateException
	{
		return encrypting ? encryptBlock(in, inOff, out, outOff) : decryptBlock(in, inOff, out, outOff);
	}

	public void reset()
	{
		System.arraycopy(IV, 0, cbcV, 0, IV.length);
		cipher.reset();
	}

	private int encryptBlock(byte in[], int inOff, byte out[], int outOff)
		throws DataLengthException, IllegalStateException
	{
		if (inOff + blockSize > in.length)
			throw new DataLengthException("input buffer too short");
		for (int i = 0; i < blockSize; i++)
			cbcV[i] ^= in[inOff + i];

		int length = cipher.processBlock(cbcV, 0, out, outOff);
		System.arraycopy(out, outOff, cbcV, 0, cbcV.length);
		return length;
	}

	private int decryptBlock(byte in[], int inOff, byte out[], int outOff)
		throws DataLengthException, IllegalStateException
	{
		if (inOff + blockSize > in.length)
			throw new DataLengthException("input buffer too short");
		System.arraycopy(in, inOff, cbcNextV, 0, blockSize);
		int length = cipher.processBlock(in, inOff, out, outOff);
		for (int i = 0; i < blockSize; i++)
			out[outOff + i] ^= cbcV[i];

		byte tmp[] = cbcV;
		cbcV = cbcNextV;
		cbcNextV = tmp;
		return length;
	}
}

⌨️ 快捷键说明

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