【发布时间】:2022-12-17 21:29:56
【问题描述】:
我使用 node.js 的 crypto 来编码和解码有效载荷
仅供参考,我是这样做的:
export const encode = (payload) => {
const cipher = crypto.createCipheriv('aes-256-cbc', env.SECRET, env.IV);
const encyptedString = cipher.update(JSON.stringify(payload), 'utf-8', 'hex') + cipher.final('hex');
return encyptedString;
};
export const decode = (encyptedString) => {
const decipher = crypto.createDecipheriv(
'aes-256-cbc',
env.SECRET,
env.IV,
);
const decryptedValue = decipher.update(encyptedString, 'hex', 'utf-8') + decipher.final('utf-8');
return JSON.parse(decryptedValue);
};
现在,如果有人可以访问有效载荷对象和加密字符串,他们是否能够找出我的env.SECRET 和env.IV?
【问题讨论】:
标签: javascript node.js encryption cryptojs