想从文件中解密一个字符串。
但是当我对来自 fs 的字符串使用 nodejs 解密时,它会给出错误“输入字符串错误”
var fs = require('fs');
var crypto = require('crypto');
function decrypt(text){
var decipher = crypto.createDecipher('aes-256-ctr', 'password')
var dec = decipher.update(text,'hex','utf8')
dec += decipher.final('utf8');
return dec;
}
fs.readFile('./file.json', 'utf8', function (err,data) {
if (err) return console.log(err);
console.log(decrypt(data));
});
试着做一个这样的字符串它可以工作
var stringInFile= "encryptedString";
console.log(decrypt(stringInFile));
来自 fs 的 console.log(data) 也给出了 'encryptedString'