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

📄 pbewithsha1and128bitrc4.java

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

/*
 * $Id: PBEWithSHA1And128BitRC4.java,v 1.2 1999/01/22 06:00:47 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/PBEWithSHA1And128BitRC4.java,v $
 * $Revision: 1.2 $
 * $Date: 1999/01/22 06:00:47 $
 * $State: Exp $
 */

import java.security.*;

import java.security.*;
import java.security.spec.*;

import javax.crypto.*;
import au.net.aba.crypto.spec.RC4KeySpec;

/**
 * This Cipher implements password based encryption (PBE) as specified
 * in PKCS#12.  This Cipher uses SHA to convert the password into a
 * RC4 Key.  RC4 is then used to encrypt or decrypt the data.
 */
public class PBEWithSHA1And128BitRC4 extends PBE
{
	public final static String ident = "$Id: PBEWithSHA1And128BitRC4.java,v 1.2 1999/01/22 06:00:47 leachbj Exp $";

	public PBEWithSHA1And128BitRC4()
	{
		super("RC4");
	}
	/**
	 * Initialises the cipher for encrypt or decryption using the
	 * provided algorithm parameters.
	 *
	 * @param opmode Encrypt/Decrypt
	 * @param salt The salt to add to the password
	 * @param iteration The iteration count for key generation
	 * @param password The actual password to use in the key generation
	 */
	protected void initCipher(
		int opmode,
		byte[] salt,
		int iteration,
		char[] password)
	{
		try
		{
			/*
			 * Convert password into bytes - PKCS#12
			 * High byte, Low Byte
			 */
			byte[] bytes = new byte[(password.length+1) * 2];
			for (int i = 0; i < password.length; i++)
			{
				int aint = (int)password[i];
				bytes[i++] = (byte)(aint >>> 8);
				bytes[i] = (byte)aint;
			}

			// Last two bytes must be zero.
			bytes[password.length] = 0;
			bytes[password.length+1] = 0;

			MessageDigest digest =
				MessageDigest.getInstance("SHA", "ABA");
			for (int i = 0; i < iteration; i++)
			{
				digest.update(bytes, 0, bytes.length);
				digest.update(salt, 0, salt.length);
			}

			byte[] digestBytes = digest.digest();

			RC4KeySpec keySpec = new RC4KeySpec(digestBytes);
			SecretKeyFactory skf =
				SecretKeyFactory.getInstance("RC4");
			SecretKey secKey = skf.generateSecret(keySpec);

			cipher.init(opmode, secKey);
		}
		catch (Exception e)
		{
			throw new ExceptionInInitializerError(e);
		}
	}
}

⌨️ 快捷键说明

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