mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-09-24 20:36:37 +08:00
26 lines
575 B
TypeScript
26 lines
575 B
TypeScript
import CryptoJS from 'crypto-js';
|
|
|
|
const CryptoSecret = '__CryptoJS_Secret__';
|
|
|
|
/**
|
|
* 加密数据
|
|
* @param data - 数据
|
|
*/
|
|
export function encrypt(data: any) {
|
|
const newData = JSON.stringify(data);
|
|
return CryptoJS.AES.encrypt(newData, CryptoSecret).toString();
|
|
}
|
|
|
|
/**
|
|
* 解密数据
|
|
* @param cipherText - 密文
|
|
*/
|
|
export function decrypt(cipherText: string) {
|
|
const bytes = CryptoJS.AES.decrypt(cipherText, CryptoSecret);
|
|
const originalText = bytes.toString(CryptoJS.enc.Utf8);
|
|
if (originalText) {
|
|
return JSON.parse(originalText);
|
|
}
|
|
return null;
|
|
}
|