我似乎無法弄清楚是什麼導致語言之間的差異。在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