/*Decryptor*/
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
/**
* Decrypt the password get form Xpress GUI
*/
public class Decryptor{
//加密
private static byte[] encrypt(int mode, byte[] password) {
try {
DESKeySpec desKeySpec = new DESKeySpec("KEY".getBytes());
SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = secretKeyFactory.generateSecret(desKeySpec);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(mode, secretKey);
return cipher.doFinal(password);
} catch (Exception e) {
return password;
}
}
//解密
public static String decrypt(String[] args) {
int length = args.length;
byte[] b = new byte[length];
for(int i = 0; i < length; i++){
b[i] = new Byte(args[i]);
}
return new String(encrypt(Cipher.DECRYPT_MODE, b));
}
}