Node.js的代碼工作(不起作用如預期)的NodeJS AES加密不起作用,因爲它在PHP
var crypto = require('crypto');
var input = '200904281000001|DOM|IND|INR|10|orderno_unique1|others|http://localhost/sample/Success.php|http://localhost/sample/failure.php|TOML';
var Key = "qcAHa6tt8s0l5NN7UWPVAQ==";
Key = new Buffer(Key || '', 'base64');
var cipher = crypto.createCipher('aes128', Key);
var actual = cipher.update(input, "utf8", "base64");
actual += cipher.final("base64");
console.log(actual);
實際輸出
bIK4D0hv2jcKP3eikoaM7ddqRee + RrT2FDOZA + c2sldyrqP + NrmgYOEXklUrSBQiU7w7e90nzFl/mpidy/Q8FD692bFLnESiNqGEQ7er44BXxFtNo6AKvpuohz31zm9JupJXL3jhOC + 47mvDHokR4b9euDzPFitTJQW55JuSyvJphOKdiXjH + lGKxXKWsODq
期望輸出
NCJ + HX6zIdrUfEedi7YC82QOUARkySblivzysFbMqaYEMPj7UfMlE4SEkDcjg + D9dE5StGJgebSOkL7UuR6fXwodcgL0CSRds0Y + hX27gKUZK45b7Tc0EjXhepwHJ/olSdWUCkwRcZcv + wxtYzOH7 + KKijJabJkU1/SF1ugExzcnqfV2wOZ9q79a4y/g3cb5
PHP CODE(按預期方式工作)
include('CryptAES.php');
//Testing key
$Key = "qcAHa6tt8s0l5NN7UWPVAQ==";
//requestparam Testing - TOML
$input ="200904281000001|DOM|IND|INR|10|unique_10005|others|http://www.yourdomain.com/paymentSuccess.php|http://www.yourdomain.com/paymentFailure.php|TOML";
$aes = new CryptAES();
$aes->set_key(base64_decode($key));
$aes->require_pkcs5();
echo $aes->encrypt($input);
如何獲取CryptAES.php? – user568109
請注意,您使用AES錯誤,您必須**使用初始化向量。 –