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

📄 ofbblockcipher.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:   OFBBlockCipher.java

package org.bouncycastle.crypto.modes;

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

public class OFBBlockCipher
	implements BlockCipher
{

	private byte IV[];
	private byte ofbV[];
	private byte ofbOutV[];
	private int blockSize;
	private BlockCipher cipher;
	private boolean encrypting;

	public OFBBlockCipher(BlockCipher cipher, int blockSize)
	{
		this.cipher = null;
		this.cipher = cipher;
		this.blockSize = blockSize / 8;
		IV = new byte[cipher.getBlockSize()];
		ofbV = new byte[cipher.getBlockSize()];
		ofbOutV = new byte[cipher.getBlockSize()];
	}

	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 < IV.length)
			{
				System.arraycopy(iv, 0, IV, IV.length - iv.length, iv.length);
				for (int i = 0; i < IV.length - iv.length; i++)
					IV[i] = 0;

			} else
			{
				System.arraycopy(iv, 0, IV, 0, IV.length);
			}
			reset();
			cipher.init(true, ivParam.getParameters());
		} else
		{
			reset();
			cipher.init(true, params);
		}
	}

	public String getAlgorithmName()
	{
		return (new StringBuilder()).append(cipher.getAlgorithmName()).append("/OFB").append(blockSize * 8).toString();
	}

	public int getBlockSize()
	{
		return blockSize;
	}

	public int processBlock(byte in[], int inOff, byte out[], int outOff)
		throws DataLengthException, IllegalStateException
	{
		if (inOff + blockSize > in.length)
			throw new DataLengthException("input buffer too short");
		if (outOff + blockSize > out.length)
			throw new DataLengthException("output buffer too short");
		cipher.processBlock(ofbV, 0, ofbOutV, 0);
		for (int i = 0; i < blockSize; i++)
			out[outOff + i] = (byte)(ofbOutV[i] ^ in[inOff + i]);

		System.arraycopy(ofbV, blockSize, ofbV, 0, ofbV.length - blockSize);
		System.arraycopy(ofbOutV, 0, ofbV, ofbV.length - blockSize, blockSize);
		return blockSize;
	}

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

⌨️ 快捷键说明

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