当我加密security sentence
时,我必须放入cipher.final();。
但是我解密时不允许放入decipher.final()。
我无法理解这种状态。
当我使用“ aes-128-gcm”时,我不需要最终方法吗?
const crypto = require('crypto');
const argo = 'aes-128-gcm';
const iv = Buffer.from(crypto.randomBytes(16)); //iv형성
const key = Buffer.from(crypto.randomBytes(16)); //key값 형성
const cipher = crypto.createCipheriv(argo, key, iv);
let result = cipher.update('security sentence','utf8', 'base64');
console.log(result);
result += cipher.final('base64');
console.log('암호화:', result);
const decipher = crypto.createDecipheriv(argo, key, iv);
let result2 = decipher.update(result, 'base64', 'utf8');
//result += decipher.final(); <- problem! occurring error.
console.log('복호화:', result2);
答案 0 :(得分:0)
虽然您没有提供返回的实际错误,但我确定它是Unsupported state or unable to authenticate data
。
话虽这么说,GCM
的{{1}}模式要求您从所得密文中导出AES
,并在解密过程中使用它。
我可以建议使用kruptein库来简化实现吗?
AuthenticationTag