公司代码是java,我的自动化测试框架是Python,遇到了公司业务登录接口的参数有加密,需要解密
公司解密代码:
public static byte[] des3DecodeECB(byte[] key, byte[] data)
throws Exception {
Key deskey = null;
DESedeKeySpec spec = new DESedeKeySpec(key);
SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
deskey = keyfactory.generateSecret(spec);
Cipher cipher = Cipher.getInstance("desede" + "/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, deskey);
byte[] bOut = cipher.doFinal(data);
return bOut;
}
public static byte[] hexStringToByte(String hex) {
int len = (hex.length() / 2);
byte[] result = new byte[len];
char[] achar = hex.toUpperCase().toCharArray();
for (int i = 0; i < len; i++) {
int pos = i * 2;
result[i] = (byte) (toByte(achar[pos]) << 4 | toByte(achar[pos + 1]));
}
return result;
}
public final class EncryptConfig {
//接口返回数据加密key,非真实key
public static final String KEY_3DESENCODE = "909bcf2b1b20235c7";
//接口接收数据解密key,非真实key
public static final String KEY_3DESDECODE = "5690dddfa28ae0";
private EncryptConfig() {
super();
}
}
上面的代码块会被下面代码调用:
byte[] decode = DESUtils.des3DecodeECB(EncryptConfig.KEY_3DESDECODE.getBytes(), HexUtil.hexStringToByte(encryptParam));
decipheringParam = new String(decode, "utf-8");
在Python中尝试过用jpype的方法调用java部分方法,然后传参感觉还是有问题,解码后是乱码
想实现在python中写一个和这个java解密一样的方法,求助!