亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? blockcipher.java

?? 面向應用的智能安全代理平臺和工具包是一個綜合網絡應用的安全共性需求而設計和實現的一個通用性的網絡信息安全應用支撐平臺
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
package au.net.aba.crypto.provider;

/*
 * $Id: BlockCipher.java,v 1.25 1999/02/11 04:28:32 leachbj Exp $
 * $Author: leachbj $
 *
 * Copyright (C) 1996-1998 Australian Business Access Pty Ltd.
 * All rights reserved.
 * 
 * Use, modification, copying and distribution of this software is subject the
 * terms and conditions of the ABA Public Licence. See the file
 * "PUBLIC_LICENCE" for additional information.
 *
 * If you have not received a copy of the Public Licence, you must destroy all
 * copies of this file immediately. 
 *
 * $Source: /aba/CVSROOT/jdk1.1/src/au.net.aba/crypto/provider/BlockCipher.java,v $
 * $Revision: 1.25 $
 * $Date: 1999/02/11 04:28:32 $
 * $State: Exp $
 */

import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import au.net.aba.crypto.spec.InlineIvParameterSpec;
import java.security.*;
import java.security.InvalidAlgorithmParameterException;
import java.security.spec.AlgorithmParameterSpec;

/**
 * This abstract class is the base class for all Block Ciphers.
 * It will perform the necessary block buffering and then
 * pass the data on through the protected interface.
 * <p>
 * This class supports PKCS#5 and NoPadding, as well
 * as supporting ECB and CBC modes.  The standard block size
 * is 8.
 * <p>
 * To implement a new block cipher it is necessary to implement
 * the three abstract methods that re-key the cipher, do encryption
 * and decryption using the current.  It may also be necessary
 * to override the <code>engineSetMode</code> method if CBC
 * or ECB are not supported.  If different padding mechanisms are
 * used <code>engineSetPadding</code> may be overridden (in
 * which case it may also be necessary to override
 * <code>engineGetOutputSize</code>).  For block sizes other than 8
 * <code>engineGetBlockSize</code> should be overridden.  Finally
 * if the algorithm supports AlgorithmParameterSpec just override
 * the <code>engineInit</code> method that accepts those parameters.
 */
public abstract class BlockCipher extends CipherSpi
{
	public final static String ident = "$Id: BlockCipher.java,v 1.25 1999/02/11 04:28:32 leachbj Exp $";

	protected final static int BLOCK_SIZE = 8;

	protected static final int ECB = 0;
	protected static final int CBC = 1;

	protected byte[] buffer;
	protected int bufferPos;

	protected int mode;
	protected boolean paddedStream;
	protected int streamMode;

	protected byte[] ivec;
	protected byte[] cbcV;

	protected boolean ivInline;
	protected boolean ivEncrypted;
	protected boolean firstBlock;

	protected Key key;

	protected SecureRandom random;

	public BlockCipher()
	{
		paddedStream = false;
		streamMode = ECB;
	}
	/**
	 * Decrypt the given block starting at the given offset and place
	 * the result in the provided buffer starting at the given offset.
	 * The input will be an exact multiple of our blocksize.
	 */
	protected abstract int decryptBlock(byte[] in, int inoff, int len,
		byte[] out, int outOff) throws BadPaddingException;
	/**
	 * Encrypt the given block starting at the given offset and place
	 * the result in the provided buffer starting at the given offset.
	 * The input will be an exact multiple of our blocksize.
	 */
	protected abstract int encryptBlock(byte[] in, int inoff, int len,
		byte[] out, int outOff) throws IllegalBlockSizeException;
	/**
	 * Encrypts or decrypts data in a single-part operation, or
	 * finishes a multiple-part operation. The data is encrypted or
	 * decrypted, depending on how this cipher was initialised. 
	 * <p>
	 * The first inputLen bytes in the input buffer, starting at
	 * inputOffset, and any input bytes that may have been buffered during
	 * a previous update operation, are processed, with padding (if
	 * requested) being applied. The result is stored in a new buffer. 
	 * <p>
	 * The cipher is reset to its initial state (uninitialised) after
	 * this call. 
	 *
	 * @param input the input buffer 
	 * @param inputOff the offset in input where the input starts 
	 * @param inputLen the input length 
	 *
	 * @exception IllegalBlockSizeException if this cipher is a block
	 * 	cipher, no padding has been requested (only in encryption
	 * 	mode), and the total input length of the data processed by
	 * 	this cipher is not a multiple of block size 
	 * @exception BadPaddingException if this cipher is in decryption mode,
	 * 	and (un)padding has been requested, but the decrypted data is
	 * 	not bounded by the appropriate padding bytes.
	 *
	 * @return the new buffer with the result 
	 */
	protected byte[] engineDoFinal(
		byte input[],
		int inputOff,
		int inputLen)
	throws IllegalBlockSizeException, BadPaddingException
	{
		/*
		 * create result array for the entire result
		 */
		byte[] output = new byte[engineGetOutputSize(inputLen)];

		try
		{
			int len = engineDoFinal(input, inputOff,
				inputLen, output, 0);
			if (len != output.length)
			{
				byte[] tmp = new byte[len];

/*
				System.out.println(
					"output " + output
					+ " output.length "
					+ (output != null ? output.length : -1)
					+ " tmp " + tmp
					+ " tmp.length "
					+ (tmp != null ? tmp.length : -1)
					+ " len " + len);
*/

				System.arraycopy(output, 0, tmp, 0, len);
				output = tmp;
			}
		}
		catch (ShortBufferException e)
		{
			// ouch this should never happen!
			throw new BadPaddingException("ShortBufferException: "
				+ e.getMessage());
		}

		return output;
	}
	/**
	 * Encrypts or decrypts data in a single-part operation, or finishes
	 * a multiple-part operation. The data is encrypted or decrypted,
	 * depending on how this cipher was initialised. 
	 * <p>
	 * The first inputLen bytes in the input buffer, starting at
	 * inputOffset, and any input bytes that may have been buffered during
	 * a previous update operation, are processed, with padding (if
	 * requested) being applied. The result is stored in the output buffer,
	 * starting at outputOffset. 
	 * <p>
	 * If the output buffer is too small to hold the result, a
	 * ShortBufferException is thrown.  In this case, repeat this call
	 * with a larger output buffer. Use getOutputSize to determine how
	 * big the output buffer should be. 
	 * 
	 * @param input the input buffer 
	 * @param inputOffset - the offset in input where the input starts 
	 * @param inputLen - the input length 
	 * @param output - the buffer for the result 
	 * @param outputOffset - the offset in output where the result is stored
	 * 
	 * @exception IllegalBlockSizeException if this cipher is a block
	 * 	cipher, no padding has been requested (only in encryption mode),
	 * 	and the total input length of the data processed by this cipher
	 * 	is not a multiple of block size 
	 * @exception ShortBufferException if the given output buffer is too
	 * 	small to hold the result 
	 * @exception BadPaddingException if this cipher is in decryption mode,
	 * 	and (un)padding has been requested, but the decrypted data is
	 * 	not bounded by the appropriate padding bytes 
	 * @returns the number of bytes stored in output 
	 */
	protected int engineDoFinal(
		byte[] input,
		int inputOff,
		int inputLen,
		byte[] output,
		int outputOff)
	throws ShortBufferException, IllegalBlockSizeException,
		BadPaddingException
	{
		int blockSize = engineGetBlockSize();
		int resultLen;

/*
		System.out.println("engineDoFinal: "
			+ " input " + input
			+ " inputOff " + inputOff
			+ " inputLen " + inputLen
			+ " output " + output
			+ " outputOff " + outputOff);
*/

		/*
		 * process any full blocks
		 */
		resultLen = processAllBlocks(input, inputOff, inputLen,
			output, outputOff);
		outputOff += resultLen;

/*
		System.out.println("engineDoFinal: bufferPos " + bufferPos);
*/

		/*
		 * process any final partial block
		 */
		if (mode == Cipher.ENCRYPT_MODE)
		{
			if (bufferPos == blockSize)
			{
				int n = processBlock(buffer, 0,
					blockSize, output, outputOff);
				outputOff += n;
				resultLen += n;
				bufferPos = 0;
			}

			if (paddedStream)
			{
				/*
				 * add PKCS7 padding
				 */
				int code = blockSize - bufferPos;
				for (; bufferPos < blockSize;
					bufferPos++)
				{
					buffer[bufferPos] = (byte)code;
				}

/*
				System.out.println("padding with code: " + code);
*/
			}

			if (bufferPos > 0)
			{
				resultLen += processBlock(buffer, 0, bufferPos,
					output, outputOff);
				bufferPos = 0;
			}
		}
		else if (mode == Cipher.DECRYPT_MODE)
		{
			if (bufferPos > 0)
			{
				if (bufferPos == blockSize)
				{
					resultLen += processBlock(buffer, 0,
						blockSize, output, outputOff);
					bufferPos = 0;
				}
				else
				{
					throw new IllegalBlockSizeException(
						"input truncated.");
				}
			}

			if (paddedStream)
			{
/*
System.out.println(outputOff + " " + test.ByteUtil.bytesToHexStr(output));
*/

				/*
				 * remove PKCS7 padding
				 */
				int count = output[outputOff
					+ blockSize - 1] & 0xff;

/*
				System.out.println("pad count = " + count);
*/
				resultLen -= count;
			}
		}

		reset();
		return resultLen;
	}
	/**
	 * Returns the block size (in bytes).  In this case 8.  This
	 * method should be overridden if the given algorithm has
	 * a different block size.
	 *
	 * @return the block size (in bytes), or 0 if the underlying
	 * 	algorithm is not a block cipher 
	 */
	protected int engineGetBlockSize()
	{
		return BLOCK_SIZE;
	}
	/**
	 * Returns the initialisation vector (IV) in a new buffer. 
	 * <p>
	 * This is useful in the context of password-based encryption or
	 * decryption, where the IV is derived from a user-provided passphrase. 
	 *
	 * @return the initialisation vector in a new buffer, or null if the
	 * 	underlying algorithm does not use an IV, or if the IV has
	 * 	not yet been set. 
	 */
	protected byte[] engineGetIV()
	{
		if (ivec != null)
		{
			int blockSize = engineGetBlockSize();
			byte[] result = new byte[blockSize];
			System.arraycopy(ivec, 0, result, 0, blockSize);

			return result;
		}

		return null;
	}
	/**
	 * Returns the length in bytes that an output buffer would need to be
	 * in order to hold the result of the next update or doFinal operation,
	 * given the input length inputLen (in bytes). 
	 * <p>
	 * This call takes into account any unprocessed (buffered) data from a
	 * previous update call, and padding. 
	 * <p>
	 * The actual output length of the next update or doFinal call may be
	 * smaller than the length returned by this method. 
	 *
	 * @param inputLen the input length (in bytes) 
	 * @return the required output buffer size (in bytes)
	 */
	protected int engineGetOutputSize(int inputLen)
	{
		int blockSize = engineGetBlockSize();

		if (firstBlock && ivInline)
		{
			if (mode == Cipher.ENCRYPT_MODE)
			{
				inputLen += blockSize;
			}
			else if (mode == Cipher.DECRYPT_MODE)
			{
				inputLen -= blockSize;
			}
		}

		inputLen += bufferPos;

		if (paddedStream)
		{
			if ((inputLen % blockSize) == 0)
			{
				inputLen += blockSize;
			}

			return ((inputLen + blockSize - 1) / blockSize)
				* blockSize;
		}

		return (inputLen / blockSize) * blockSize;
	}
	/**
	 * Returns the parameters used with this cipher. 
	 * <p>
	 * The returned parameters may be the same that were used to initialise
	 * this cipher, or may contain the default set of parameters or a set of
	 * randomly generated parameters used by the underlying cipher
	 * implementation (provided that the underlying cipher implementation
	 * uses a default set of parameters or creates new parameters if it
	 * needs parameters but was not initialised with any).
	 *
	 * @return the parameters used with this cipher, or null if this cipher
	 *     does not use any parameters.
	 */
	protected AlgorithmParameters engineGetParameters()
	{
		return null;
	}
	/**
	 * Initialises this cipher with a key, a set of algorithm parameters,
	 * and a source of randomness.
	 * <p>
	 * The cipher is initialised for encryption or decryption, depending
	 * on the value of opmode.
	 * <p>
	 * If this cipher requires any algorithm parameters and params is
	 * null, the underlying cipher implementation is supposed to generate
	 * the required parameters itself (using provider-specific default or
	 * random values) if it is being initialised for encryption, and
	 * raise an InvalidAlgorithmParameterException if it is being
	 * initialised for decryption. The generated parameters can be
	 * retrieved using engineGetParameters or engineGetIV (if the
	 * parameter is an IV). 
	 * <p>
	 * If this cipher (including its underlying feedback or padding
	 * scheme) requires any random bytes (e.g., for parameter
	 * generation), it will get them from random. 
	 * <p>
	 * Note that when a Cipher object is initialised, it loses all
	 * previously-acquired state. In other words, initialising a Cipher
	 * is equivalent to creating a new instance of that Cipher and
	 * initialising it.
	 * <p>
	 * @param opmode the operation mode of this cipher (this is either
	 *    ENCRYPT_MODE or DECRYPT_MODE)
	 * @param key the encryption key
	 * @param params the algorithm parameters
	 * @param random the source of randomness
	 * @exception InvalidKeyException if the given key is
	 *    inappropriate for initialising this cipher
	 * @exception InvalidAlgorithmParameterException if the given algorithm
	 * 	parameters are inappropriate for this cipher, or if this
	 * 	cipher is being initialised fro decryption and requires
	 * 	algorithm parameters and params is null
	 */
	protected void engineInit(
		int opmode,
		Key key,
		AlgorithmParameters params,
		SecureRandom random)
	throws InvalidKeyException, InvalidAlgorithmParameterException
	{
		AlgorithmParameterSpec spec = null;
		if (params != null)
		{
			try
			{
				spec = params.getParameterSpec(IvParameterSpec.class);
			}
			catch (Exception e)
			{
				try
				{
					spec = params.getParameterSpec(InlineIvParameterSpec.class);
				}
				catch (Exception e2)
				{
					throw new InvalidAlgorithmParameterException(
						"Processing error: " + e2);
				
				}
			}
		}

		engineInit(opmode, key, spec, random);
	}
	/**
	 * Initialises this cipher with a key and a source of randomness.  
	 * <p>
	 * The cipher is initialised for encryption or decryption, depending
	 * on the value of opmode.
	 * <p>
	 * If this cipher requires any algorithm parameters that cannot be
	 * derived from the given key, the underlying cipher implementation
	 * is supposed to generate the required parameters itself (using
	 * provider-specific default or random values) if it is being
	 * initialised for encryption, and raise an InvalidKeyException if it
	 * is being initialised for decryption. The generated parameters can
	 * be retrieved using engineGetParameters or engineGetIV (if the
	 * parameter is an IV).
	 * <p>
	 * If this cipher (including its underlying feedback or padding
	 * scheme) requires any random bytes (e.g., for parameter
	 * generation), it will get them from random.
	 * <p>
	 * Note that when a Cipher object is initialised, it loses all
	 * previously-acquired state. In other words, initialising a Cipher
	 * is equivalent to creating a new instance of that Cipher and
	 * initialising it

	 * @param opmode the operation mode of this cipher (this is either
	 *			ENCRYPT_MODE or DECRYPT_MODE) 
	 * @param key the encryption key 
	 * @param random the source of randomness 
	 * @exception InvalidKeyException if the given key is inappropriate
	 *			for initialising this cipher 
	 */
	protected void engineInit(
		int opmode,
		Key key,
		SecureRandom random)
	throws InvalidKeyException
	{
		try
		{
			engineInit(opmode, key, (AlgorithmParameterSpec)null,
				random);
		}
		catch (InvalidAlgorithmParameterException e)
		{
			// ouch this should never happen!
			throw new InvalidKeyException(
				"InvalidAlgorithmParameterException: "
				+ e.getMessage());
		}
	}
	/**
	 * Initialises this cipher with a key, a set of algorithm parameters,
	 * and a source of randomness.
	 * <p>
	 * The cipher is initialised for encryption or decryption, depending
	 * on the value of opmode.
	 * <p>
	 * If this cipher requires any algorithm parameters and params is
	 * null, the underlying cipher implementation is supposed to generate
	 * the required parameters itself (using provider-specific default or
	 * random values) if it is being initialised for encryption, and
	 * raise an InvalidAlgorithmParameterException if it is being
	 * initialised for decryption. The generated parameters can be
	 * retrieved using engineGetParameters or engineGetIV (if the
	 * parameter is an IV).
	 * <p>
	 * If this cipher (including its underlying feedback or padding
	 * scheme) requires any random bytes (e.g., for parameter
	 * generation), it will get them from random.
	 * <p>
	 * Note that when a Cipher object is initialised, it loses all
	 * previously-acquired state. In other words, initialising a Cipher
	 * is equivalent to creating a new instance of that Cipher and
	 * initialising it.
	 * <p>
	 * @param opmode the operation mode of this cipher (this is either
	 *	ENCRYPT_MODE or DECRYPT_MODE) 
	 * @param key the encryption key 
	 * @param params the algorithm parameters
	 * @param random the source of randomness 
	 *
	 * @exception InvalidKeyException if the given key is inappropriate

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲综合丝袜美腿| 精品福利一区二区三区| 国产一区二区三区最好精华液| 国产三级精品三级在线专区| 在线成人av影院| 欧美性三三影院| 91视频在线看| 国产精品 日产精品 欧美精品| 亚洲成人精品一区| 亚洲午夜久久久| 中文字幕在线观看不卡视频| 久久免费视频一区| www一区二区| 欧美国产精品一区| 日本一区二区三区国色天香| 亚洲精品在线电影| 国产精品美女久久久久aⅴ| 91麻豆免费在线观看| 成人av资源在线| 国产精品一二三区在线| 国产在线一区观看| 国产一区二区三区在线观看精品 | 国产中文字幕一区| 久久99精品久久久久久久久久久久 | 日韩 欧美一区二区三区| 亚洲一区二区三区四区的| 亚洲国产成人av网| 奇米综合一区二区三区精品视频| 亚洲成人免费在线| 日韩精品免费专区| 国产精品自产自拍| 成人一道本在线| 欧美自拍偷拍一区| 91麻豆精品久久久久蜜臀| 日韩女优毛片在线| 国产欧美一区在线| 一区二区成人在线| 九九热在线视频观看这里只有精品| 九色porny丨国产精品| 成人性生交大片免费看在线播放 | 精品一区二区三区免费| 国产成人精品www牛牛影视| 99热这里都是精品| 欧美精品丝袜久久久中文字幕| 国产婷婷色一区二区三区在线| 亚洲国产一区视频| 99精品欧美一区二区蜜桃免费 | 国产真实乱子伦精品视频| 99久久久国产精品| 2021中文字幕一区亚洲| 亚洲国产精品嫩草影院| 成人福利视频在线| 久久―日本道色综合久久| 亚洲国产成人tv| 91精彩视频在线| 中日韩av电影| 99久久精品国产导航| 国产亚洲精品bt天堂精选| 青青青伊人色综合久久| 91超碰这里只有精品国产| 午夜影院久久久| 欧美日韩视频第一区| 日韩高清不卡一区二区| 久久综合九色综合欧美就去吻| 国产精品一区二区三区乱码 | 久久一夜天堂av一区二区三区| 日本vs亚洲vs韩国一区三区二区| 欧美久久久久久久久中文字幕| 日本系列欧美系列| 久久免费电影网| 国产精品一区二区三区乱码| 精品国一区二区三区| 韩国精品免费视频| 国产欧美日韩精品在线| 成人av免费网站| 亚洲国产视频在线| 欧美成人vr18sexvr| 韩国一区二区三区| 中文字幕制服丝袜一区二区三区| 成人国产精品免费观看| 一区二区三区在线视频观看58| 9191成人精品久久| 国产精品一二一区| 亚洲综合一区二区三区| 精品日本一线二线三线不卡| 国产美女娇喘av呻吟久久| 久久久久久久久99精品| 在线视频国内自拍亚洲视频| 青娱乐精品视频在线| 国产亚洲欧美激情| 欧美性做爰猛烈叫床潮| 国产精品白丝jk白祙喷水网站| 自拍偷拍国产亚洲| 久久婷婷色综合| 91看片淫黄大片一级在线观看| 蜜臀精品久久久久久蜜臀| 国产精品久久久久影院老司| 日韩一区二区三区高清免费看看| 成人久久视频在线观看| 久久精品久久综合| 亚洲精品videosex极品| 精品国产1区二区| 精品视频在线看| 99精品偷自拍| 国产高清精品在线| 爽爽淫人综合网网站| 亚洲欧美国产毛片在线| 欧美—级在线免费片| 精品国产一区二区三区久久久蜜月 | 天堂蜜桃91精品| 一区二区三区不卡视频在线观看| 国产欧美日韩在线观看| 精品剧情在线观看| 日韩欧美一二三四区| 欧美日韩一区二区三区在线看| 一本大道久久a久久综合婷婷| 高清在线不卡av| 国产成a人亚洲精品| 国产老妇另类xxxxx| 国产精品99久久久| 成人午夜精品一区二区三区| 国产91精品精华液一区二区三区| 国内精品不卡在线| 国产精品一区二区在线观看不卡| 国产在线国偷精品免费看| 精品一区二区日韩| 国产精品综合在线视频| 国产成人av一区二区| 成a人片国产精品| 91久久精品一区二区三| 欧美人妇做爰xxxⅹ性高电影 | 国产福利电影一区二区三区| 国产电影一区二区三区| 国产一区二区三区电影在线观看| 成人激情av网| 欧美日韩久久不卡| 久久精品日产第一区二区三区高清版 | 欧美一区二区美女| 久久久久久久综合狠狠综合| 亚洲天堂av老司机| 捆绑变态av一区二区三区| 成人性生交大片免费看在线播放| 91久久一区二区| 91精品国产美女浴室洗澡无遮挡| 国产日产欧美一区| 日韩成人午夜电影| 91香蕉视频在线| 精品欧美乱码久久久久久1区2区| 中文字幕中文字幕一区二区| 日本美女视频一区二区| 一本久道中文字幕精品亚洲嫩| 日韩小视频在线观看专区| 亚洲三级视频在线观看| 国产乱人伦偷精品视频免下载| 欧美午夜在线观看| 综合久久久久久| 国产精品一区二区x88av| 日韩你懂的在线观看| 亚洲图片欧美一区| 欧洲精品视频在线观看| 中文字幕一区三区| 春色校园综合激情亚洲| 国产欧美va欧美不卡在线| 精品影视av免费| 欧美成人福利视频| 日日噜噜夜夜狠狠视频欧美人| 色婷婷综合激情| 日韩伦理免费电影| 色悠悠久久综合| 亚洲女同ⅹxx女同tv| av亚洲精华国产精华精| 日本一区二区成人在线| 精品午夜一区二区三区在线观看| 日韩欧美精品在线视频| 激情深爱一区二区| 久久看人人爽人人| 成人黄色免费短视频| 国产精品丝袜在线| 91久久精品国产91性色tv| 亚洲韩国一区二区三区| 欧美一区二区三区免费大片| 麻豆精品视频在线| 久久久www成人免费无遮挡大片| 国产·精品毛片| 亚洲三级久久久| 7777精品伊人久久久大香线蕉| 国产精品99久久久久久有的能看| 一区在线中文字幕| 欧美日韩精品一区二区三区蜜桃 | 色哟哟在线观看一区二区三区| 亚洲一区二区免费视频| 日韩欧美一级片| 暴力调教一区二区三区| 日本在线不卡视频一二三区| 日本一区二区三区电影| 欧美一区二区三区在线观看| 成人午夜伦理影院| 欧美aaa在线| 亚洲尤物在线视频观看| 久久亚洲影视婷婷|