48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
import CryptoJS from 'crypto-js'
|
|
import CRC32 from 'crc-32'
|
|
|
|
// aes加密
|
|
export function encrypt(code, json_row) {
|
|
// 循环冗余校验
|
|
let aesKey = CRC32.str(code)
|
|
// 取八位
|
|
aesKey = aesKey.toString().slice(0,8)
|
|
// 字符串化
|
|
let json_str = JSON.stringify(json_row)
|
|
// 加密
|
|
return CryptoJS.AES.encrypt(json_str, CryptoJS.enc.Utf8.parse(aesKey), {
|
|
mode: CryptoJS.mode.ECB,
|
|
padding: CryptoJS.pad.Pkcs7
|
|
}).toString();
|
|
}
|
|
|
|
// aes解密
|
|
export function decrypt(code, encrypt_str) {
|
|
// 循环冗余校验
|
|
let aesKey = CRC32.str(code)
|
|
// 取八位
|
|
aesKey = aesKey.toString().slice(0,8)
|
|
// 解密
|
|
return CryptoJS.AES.decrypt(encrypt_str, CryptoJS.enc.Utf8.parse(aesKey), {
|
|
mode: CryptoJS.mode.ECB,
|
|
padding: CryptoJS.pad.Pkcs7
|
|
}).toString(CryptoJS.enc.Utf8);
|
|
}
|
|
|
|
// aes加密用户密码
|
|
export function encryptMainCode(code) {
|
|
let default_key = 'e08b44a351a3'
|
|
return CryptoJS.AES.encrypt(code, CryptoJS.enc.Utf8.parse(default_key), {
|
|
mode: CryptoJS.mode.ECB,
|
|
padding: CryptoJS.pad.Pkcs7
|
|
}).toString();
|
|
}
|
|
|
|
// aes解密用户密码
|
|
export function decryptMainCode(row_code) {
|
|
let default_key = 'e08b44a351a3'
|
|
return CryptoJS.AES.decrypt(row_code, CryptoJS.enc.Utf8.parse(default_key), {
|
|
mode: CryptoJS.mode.ECB,
|
|
padding: CryptoJS.pad.Pkcs7
|
|
}).toString(CryptoJS.enc.Utf8);
|
|
} |