package com.xxx;
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class wd
{
private static String strDefaultKey = "national";
private Cipher decryptCipher = (Cipher)null;
private Cipher encryptCipher = (Cipher)null;
public wd()
throws Exception
{
this(strDefaultKey);
}
public wd(String paramString)
{
try
{
paramString = getKey(paramString.getBytes());
this.encryptCipher = Cipher.getInstance("DES");
this.encryptCipher.init(1, paramString);
this.decryptCipher = Cipher.getInstance("DES");
this.decryptCipher.init(2, paramString);
return;
}
catch (Exception paramString)
{
paramString.printStackTrace();
}
}
public static String byteArr2HexStr(byte[] paramArrayOfByte)
throws Exception
{
int k = paramArrayOfByte.length;
StringBuffer localStringBuffer = new StringBuffer(k * 2);
int i = 0;
if (i >= k) {
return localStringBuffer.toString();
}
int j = paramArrayOfByte[i];
for (;;)
{
if (j >= 0)
{
if (j < 16) {
localStringBuffer.append('0');
}
localStringBuffer.append(Integer.toString(j, 16));
i += 1;
break;
}
j += 256;
}
}
private Key getKey(byte[] paramArrayOfByte)
throws Exception
{
byte[] arrayOfByte = new byte[8];
int i = 0;
for (;;)
{
if ((i >= paramArrayOfByte.length) || (i >= arrayOfByte.length)) {
return new SecretKeySpec(arrayOfByte, "DES");
}
arrayOfByte[i] = paramArrayOfByte[i];
i += 1;
}
}
public static byte[] hexStr2ByteArr(String paramString)
throws Exception
{
paramString = paramString.getBytes();
int j = paramString.length;
byte[] arrayOfByte = new byte[j / 2];
int i = 0;
for (;;)
{
if (i >= j) {
return arrayOfByte;
}
String str = new String(paramString, i, 2);
arrayOfByte[(i / 2)] = ((byte)Integer.parseInt(str, 16));
i += 2;
}
}
public String decrypt(String paramString)
throws Exception
{
return new String(decrypt(hexStr2ByteArr(paramString)));
}
public byte[] decrypt(byte[] paramArrayOfByte)
throws Exception
{
return this.decryptCipher.doFinal(paramArrayOfByte);
}
public String encrypt(String paramString)
throws Exception
{
return byteArr2HexStr(encrypt(paramString.getBytes()));
}
public byte[] encrypt(byte[] paramArrayOfByte)
throws Exception
{
return this.encryptCipher.doFinal(paramArrayOfByte);
}
}
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class wd
{
private static String strDefaultKey = "national";
private Cipher decryptCipher = (Cipher)null;
private Cipher encryptCipher = (Cipher)null;
public wd()
throws Exception
{
this(strDefaultKey);
}
public wd(String paramString)
{
try
{
paramString = getKey(paramString.getBytes());
this.encryptCipher = Cipher.getInstance("DES");
this.encryptCipher.init(1, paramString);
this.decryptCipher = Cipher.getInstance("DES");
this.decryptCipher.init(2, paramString);
return;
}
catch (Exception paramString)
{
paramString.printStackTrace();
}
}
public static String byteArr2HexStr(byte[] paramArrayOfByte)
throws Exception
{
int k = paramArrayOfByte.length;
StringBuffer localStringBuffer = new StringBuffer(k * 2);
int i = 0;
if (i >= k) {
return localStringBuffer.toString();
}
int j = paramArrayOfByte[i];
for (;;)
{
if (j >= 0)
{
if (j < 16) {
localStringBuffer.append('0');
}
localStringBuffer.append(Integer.toString(j, 16));
i += 1;
break;
}
j += 256;
}
}
private Key getKey(byte[] paramArrayOfByte)
throws Exception
{
byte[] arrayOfByte = new byte[8];
int i = 0;
for (;;)
{
if ((i >= paramArrayOfByte.length) || (i >= arrayOfByte.length)) {
return new SecretKeySpec(arrayOfByte, "DES");
}
arrayOfByte[i] = paramArrayOfByte[i];
i += 1;
}
}
public static byte[] hexStr2ByteArr(String paramString)
throws Exception
{
paramString = paramString.getBytes();
int j = paramString.length;
byte[] arrayOfByte = new byte[j / 2];
int i = 0;
for (;;)
{
if (i >= j) {
return arrayOfByte;
}
String str = new String(paramString, i, 2);
arrayOfByte[(i / 2)] = ((byte)Integer.parseInt(str, 16));
i += 2;
}
}
public String decrypt(String paramString)
throws Exception
{
return new String(decrypt(hexStr2ByteArr(paramString)));
}
public byte[] decrypt(byte[] paramArrayOfByte)
throws Exception
{
return this.decryptCipher.doFinal(paramArrayOfByte);
}
public String encrypt(String paramString)
throws Exception
{
return byteArr2HexStr(encrypt(paramString.getBytes()));
}
public byte[] encrypt(byte[] paramArrayOfByte)
throws Exception
{
return this.encryptCipher.doFinal(paramArrayOfByte);
}
}