js 加密 crypto.js
2021-01-23 05:12
标签:art com imp exp target 十六 pre rom src https://www.jianshu.com/p/95d8eeb8301f js 加密 crypto.js 标签:art com imp exp target 十六 pre rom src 原文地址:https://www.cnblogs.com/zhanglw456/p/13280928.html1
import CryptoJS from ‘crypto-js‘
export const encrypt = (word) => {
var key = CryptoJS.enc.Utf8.parse("46cc793c53dc451b");
var srcs = CryptoJS.enc.Utf8.parse(word);
var encrypted = CryptoJS.AES.encrypt(srcs, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
}
/**
* 解密
*/
export const decrypt = (word) => {
var key = CryptoJS.enc.Utf8.parse("46cc793c53dc451b");
var decrypt = CryptoJS.AES.decrypt(word, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}
2
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();
}
export default {
Decrypt ,
Encrypt
}
https://www.jianshu.com/p/a47477e8126a
https://blog.csdn.net/vieri_32/article/details/48345023
https://blog.csdn.net/qq_28205153/article/details/55798628
下一篇:css 实现手风琴效果