日期:2014-05-17 浏览次数:20821 次
import java.security.Key;
import java.util.Vector;
import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
public class KeyTest {
// 密钥算法
public static final String KEY_ALGORITHM = "DES";
// 加密/解密算法/工作模式/填充方式(无填充)
public static final String CIPHER_ALGORITHM4CCB = "DES/CBC/NOPadding";
// CBC向量(标准DESCBC向量无偏移)
public static final byte[] EncryptionIV4CCB = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };
// 用于建立十六进制字符的输出的小写字符数组
private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
// 用于建立十六进制字符的输出的大写字符数组
private static final char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
/**
* @param args
* @throws Throwable
*/
public static void main(String[] args) throws Throwable {
// 主密钥
String primaryKey = "f3cea8825c3610ea";
byte[] primaryKey2 = hexStringToByte(primaryKey);
// pinkey
String pinkeyEn = "a60446f56d7a87db";
byte[] pinkeyEn2 = hexStringToByte(pinkeyEn);
// mackey
String mackeyEn = "555ac13972cb897b";
byte[] mackeyEn2 = hexStringToByte(mackeyEn);
System.out.println("解密后的pinkey:" + encodeHexStr(getDESDecrypt4CCB(pinkeyEn2, primaryKey2)));