更新:我终于设法按照第三方服务的要求重新创建了整个 Java 代码。我必须补充一点,一些使用的库已被弃用,但我无能为力,因为那是对方正在使用的,我必须遵守。
Java 代码
SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(),
"AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(1, secretKeySpec);
byte[] aBytes = cipher.doFinal(inputString.getBytes());
输入键:xxxxxxxxyyyyyyyy
输入文本:maryhadalittlelamb
输出:Z22GETg3Anl92%2BoyqdVWs9haQveaZxkDn8sQYP08iCY%3D
node.js 代码
var cipher = crypto.createCipher('aes-128-ecb', key);
var encryptedPassword = cipher.update(text, 'utf8', 'base64');
encryptedPassword += cipher.final('base64');
console.log(encryptedPassword);
输入键:xxxxxxxxyyyyyyyy
输入文本:maryhadalittlelamb
输出:mnqrpA2eqAhmseTrkBtH3YSGMoFs+ECPUamVd8/bgAQ=
相同输入字符串和键的输出对于两者都是不同的。事实上,node.js 是不同的,但 base64 看起来还是一样的。
我对这些东西还很陌生,因此我已经失去了可能。