我有两种加密和解密方法:
function encrypt(text, guid){
var textBuffer = new Buffer(text, 'utf8');
var cipher = crypto.createCipher('aes-256-ctr',guid);
cipher.setAutoPadding(false);
cipher.write(textBuffer);
cipher.end();
var cipheredText = cipher.read().toString('hex');
return cipheredText;
}
function decrypt(encrypted, guid){
try{
var hexBuffer = new Buffer(encrypted, 'hex');
var decipher = crypto.createDecipher('aes-256-ctr',guid);
decipher.setAutoPadding(false);
decipher.write(hexBuffer);
decipher.end();
var decipheredText = decipher.read().toString('utf8');
return decipheredText;
}catch(error){
return "";
}
}
当呼叫"解密"它可以在加密后的几秒钟内完成解密,但是当呼叫需要几分钟再次调用时,它会将文本解密为其他内容。 我能做错什么?参数相同。