如何从 Node.Js 中的 phpseclib 解密密码 AES

How to decrypt cipher AES from phpseclib in Node.Js

我尝试使用 phpseclib(默认)加密

include 'AES.php';
$aes = new Crypt_AES();
$aes->setKey('abcdefghijklmnop');

$encrypt = $aes->encrypt("hello");
echo base64_encode($encrypt);
echo "<br />";
echo $aes->decrypt($encrypt);

输出:

CAX/zDb/Vdu/063a7fE+qQ==
hello

和Node.js用于解密

var CryptoJS = require("crypto-js");
var key = 'abcdefghijklmnop';

// Decrypt
var bytes  =     CryptoJS.AES.decrypt(CryptoJS.enc.Base64.parse('CAX/zDb/Vdu/063a7fE+qQ=='), key);
var plaintext = bytes.toString(CryptoJS.enc.Utf8);

console.log(plaintext);

但是没有输出。

var CryptoJS = require("crypto-js");
var key = CryptoJS.enc.Utf8.parse('abcdefghijklmnop');
var iv = CryptoJS.enc.Hex.parse('00000000000000000000000000000000');

// Decrypt
var bytes  =     CryptoJS.AES.decrypt({ciphertext: CryptoJS.enc.Base64.parse('CAX/zDb/Vdu/063a7fE+qQ==')}, key, {iv: iv});
var plaintext = bytes.toString(CryptoJS.enc.Utf8);

console.log(plaintext);

这对我有用。