我有 2 个 scripts,一个是 node.js,另外一个是 bash.sh
node.js
// Nodejs encryption with CTR
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'my_password';
function encrypt(text){
var cipher = crypto.createCipher(algorithm,password)
var crypted = cipher.update(text, 'utf8', 'hex')
crypted += cipher.final('hex');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher(algorithm,password)
var dec = decipher.update(text,'hex','utf8')
dec += decipher.final('utf8');
return dec;
}
var hw = encrypt("14:3b:62:6c:b5:44")
console.log(hw);
console.log(decrypt(hw));
bash script
#!/bin/bash
#
echo -n "14:3b:62:6c:b5:44" |\
openssl enc -a -e -aes-256-ctr -nosalt -pass pass:my_password |\
xxd -p
但这 2 个程序得到了不同的结果
$ node node_script.js
ecb091d31243c56f41acc18bcdab1523c7
14:3b:62:6c:b5:44
$ ./bash_script.sh
374c435230784a4478573942724d474c7a6173564938633d0a
我哪里做错了呢?谢谢