js 加密和解密
2024-09-08 17:19:43
// aes对称加密
const CryptoJS = require('crypto-js'); //引用AES源码js const key = CryptoJS.enc.Utf8.parse("1234123412ABCDEF"); //十六位十六进制数作为密钥
const iv = CryptoJS.enc.Utf8.parse('ABCDEF1234123412'); //十六位十六进制数作为密钥偏移量 //解密方法
function Decrypt(word) {
let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
let decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
return decryptedStr.toString();
} //加密方法
function Encrypt(word) {
let srcs = CryptoJS.enc.Utf8.parse(word);
let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
return encrypted.ciphertext.toString().toUpperCase();
}
最新文章
- iMetro
- [Linux]cmd to use
- UDP模式聊天
- Windows Server 2008 R2 每隔一段时间自动关机解决办法
- 《深入理解bootstrap》读书笔记:第一章 入门准备
- erlang尾递归的概括
- MySQL数据库获取多个汉字拼音的首字母函数
- SCCM 2007 R2部署、操作详解系列之概念
- app视觉设计艺术(读书笔记)
- [cocoapods] 如何卸载工程里的cocoapods
- codeforces C. Restore Graph
- LeetCode——Rotate List
- (4)activiti之uel表达式
- Jmeter + Ant 测试环境搭建 及解决问题: the <;jmeter>; type doesn&#39;t support nested text data
- 深入理解Java虚拟机阅读心得(三)
- vimrc同步文档
- 2、jeecg 笔记之 t:dictSelect 或 t:dgCol 自定义字典
- C基础学习笔记
- Running kubernetes on windows
- 重写nyoj2——括号匹配