在~/plugins下新建 encrytion.js文件
const crypto = require('crypto');
export default {
aesEncrypt(data, key){
try{
var salt = key.toString() + 'manbanzhen'; // 定义盐值
const cipher = crypto.createCipher('aes192', salt); // 采用aes192加密方式
var crypted = cipher.update(data, 'utf8', 'hex'); // 加密
crypted += cipher.final('hex');
return crypted;
}catch (e) { // 加捕获是为了在验证失败的时候,直接让用户重新登陆
alert("检测到存在安全异常,请检查当前网络环境并重新登录!");
window.location.href = '/login'
}
},
aesDecrypt(encrypted, key) {
try{
var salt = key.toString() + 'manbanzhen'; // 定义盐值
const decipher = crypto.createDecipher('aes192', salt); // 解密 aes192
var decrypted = decipher.update(encrypted, 'hex', 'utf8'); //解密
decrypted += decipher.final('utf8');
return decrypted;
}catch (e) { // 加捕获是为了在验证失败的时候,直接让用户重新登陆
// console.log("error*-**--*-")
alert("检测到存在安全异常,请检查当前网络环境并重新登录!");
window.location.href = '/login';
}
}
}
</

本文详细介绍了如何在Node.js环境中使用AES192算法进行数据的加密与解密操作,通过具体的代码示例展示了创建加密模块的过程,并提供了如何在项目中调用该模块的方法。
最低0.47元/天 解锁文章
1088

被折叠的 条评论
为什么被折叠?



