- 安装
yarn add crypto-js
- 引入
import { AES, enc } from "crypto-js"
- 数据源
let info = {
name: "kaka",
age: 55,
message: "这是一句话",
gender: "male",
favourite: [
{
name: "apple",
price: 1
},
{
name: "orange",
price: 12
}
]
}
- 加密
// 加密
let encrypt = AES.encrypt(
JSON.stringify(info),
"ppppassword"
).toString();
// 存入 sessionStorage
utils.setSession("info", encrypt);
- 解密
// 从 sessionStorage 中取出并解密
let bytes = AES.decrypt(utils.getSession("info"), "ppppassword");
let decrypt = JSON.parse(bytes.toString(enc.Utf8));
网友评论