Commit 5cfaa7e7 by 蒋勇

d

parent ee01ac9a
const CryptoJS = require("crypto-js");
let u = { "id": 12, "nickName": "好好学习", "mobile": "13381139519", "isAdmin": false }
var str = JSON.stringify(u);
// 密钥 16 位
var key = 'dc35d3a0bd6641d891d3233b5286225a';
// 初始向量 initial vector 16 位
var iv = '92bcc33e807d43fc8265ee5210e37923';
// key 和 iv 可以一致
key = CryptoJS.enc.Utf8.parse(key);
iv = CryptoJS.enc.Utf8.parse(iv);
var encrypted = CryptoJS.AES.encrypt(str, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
// 转换为字符串
encrypted = encrypted.toString();
console.log("加密串", encrypted)
console.log("加密串", encodeURIComponent(encrypted))
// mode 支持 CBC、CFB、CTR、ECB、OFB, 默认 CBC
// padding 支持 Pkcs7、AnsiX923、Iso10126
// NoPadding、ZeroPadding, 默认 Pkcs7, 即 Pkcs5
// 解密
var decrypted = CryptoJS.AES.decrypt(encrypted, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
decrypted = CryptoJS.enc.Utf8.stringify(decrypted);
console.log("解密串", decrypted)
// var a=[1,2] // var a=[1,2]
// var b=[3,4] // var b=[3,4]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment