我似乎无法弄清楚是什么导致语言之间的差异。在Java中,我有:无法转换解密代码usingg Blowfish ECB从Java到Node.js
byte[] buf = Base64.getDecoder().decode("AutMdzthDvPlE+UnhcHa2h4UZGPdme7t");
System.out.println(buf.length);
String key = "" + 2270457870L;
byte[] keyBytes = key.getBytes("UTF8");
System.out.println(keyBytes.length);
Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(keyBytes, "Blowfish"));
byte[] newBytes = cipher.doFinal(buf);
System.out.println(newBytes.length);
System.out.println(Arrays.toString(newBytes));
(在http://ideone.com/0dXuJL可运行在线)
然后在节点我变成了这样:
const buf = Buffer.from("AutMdzthDvPlE+UnhcHa2h4UZGPdme7t");
console.log(buf.length);
const keyBytes = Buffer.from('2270457870', 'utf8');
console.log(keyBytes.length);
const decipher = require('crypto').createDecipher('bf-ecb', keyBytes);
const buffers = [];
buffers.push(decipher.update(buf));
buffers.push(decipher.final());
const newBytes = Buffer.concat(buffers);
console.log(newBytes.length);
console.log(newBytes);
(可运行在网上https://tonicdev.com/paulbgd/57b66c8ea0630d1400081ad0)
,它输出错误:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
基于64位只是一个错误,我当复制它,但我没有意识到createDecipher期待一个密码!万分感谢。 – PaulBGD