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

📄 desede.java

📁 面向应用的智能安全代理平台和工具包是一个综合网络应用的安全共性需求而设计和实现的一个通用性的网络信息安全应用支撑平台
💻 JAVA
字号:
package au.net.aba.crypto.provider;

/*
 * $Id: DESede.java,v 1.11 1999/01/18 05:01:40 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/DESede.java,v $
 * $Revision: 1.11 $
 * $Date: 1999/01/18 05:01:40 $
 * $State: Exp $
 */

import java.security.*;

import javax.crypto.*;
import javax.crypto.spec.*;

/**
 * A class that provides DES-EDE encryption.
 */
public class DESede extends DES
{
	public final static String ident = "$Id: DESede.java,v 1.11 1999/01/18 05:01:40 leachbj Exp $";

	private int[] Kn2;
	private int[] Kn3;

	public DESede()
	{
		Kn2 = new int[32];
		Kn3 = new int[32];
	}
	protected int decryptBlock(
		byte[] in,
		int inOff,
		int len,
		byte[] out,
		int outOff)
	throws BadPaddingException
	{
		if (len != BLOCK_SIZE)
		{
			throw new BadPaddingException("Datasize less than block size.");
		}

		scrunch(in, inOff, work);
		desfunc(work, Kn3);
		desfunc(work, Kn2);
		desfunc(work, Kn1);
		unscrunch(work, out, outOff);

		return BLOCK_SIZE;
	}
	protected int encryptBlock(
		byte[] in,
		int inOff,
		int len,
		byte[] out,
		int outOff)
	throws IllegalBlockSizeException
	{
		if (len != BLOCK_SIZE)
		{
			throw new IllegalBlockSizeException("Datasize less than block size.");
		}

		scrunch(in, inOff, work);
		desfunc(work, Kn1);
		desfunc(work, Kn2);
		desfunc(work, Kn3);
		unscrunch(work, out, outOff);

		return len;
	}
	/**
	 * Set up the keys for the DES EDE cipher.
	 */
	protected void setKey(
		Key key)
	throws InvalidKeyException
	{
		byte[]	k1, k2, k3;

		if (!((key instanceof DESedeKey)
				|| (key instanceof SecretKeySpec)))
		{
			throw new InvalidKeyException("not a DESede Key");
		}

		byte[] keyBytes = key.getEncoded();

		k1 = new byte[DESKeySpec.DES_KEY_LEN];
		System.arraycopy(keyBytes, 0, k1, 0, DESKeySpec.DES_KEY_LEN);

		k2 = new byte[DESKeySpec.DES_KEY_LEN];
		System.arraycopy(keyBytes, DESKeySpec.DES_KEY_LEN, k2, 0,
			DESKeySpec.DES_KEY_LEN);

		k3 = new byte[DESKeySpec.DES_KEY_LEN];
		System.arraycopy(keyBytes, 2 * DESKeySpec.DES_KEY_LEN, k3, 0,
			DESKeySpec.DES_KEY_LEN);

		if (mode == Cipher.ENCRYPT_MODE)
		{
			prepareKeys(Cipher.ENCRYPT_MODE, k1, Kn1);
			prepareKeys(Cipher.DECRYPT_MODE, k2, Kn2);
			prepareKeys(Cipher.ENCRYPT_MODE, k3, Kn3);
		}
		else
		{
			prepareKeys(Cipher.DECRYPT_MODE, k1, Kn1);
			prepareKeys(Cipher.ENCRYPT_MODE, k2, Kn2);
			prepareKeys(Cipher.DECRYPT_MODE, k3, Kn3);
		}
	}
}

⌨️ 快捷键说明

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