@10yun/cv-js-utils
Version:
常用 js-utils 工具类库
16 lines (12 loc) • 403 B
JavaScript
import CryptoJS from 'crypto-js';
const CryptoSecret = '__CRYPTO_SECRET__';
export function enCrypto(data) {
const str = JSON.stringify(data);
return CryptoJS.AES.encrypt(str, CryptoSecret).toString();
}
export function deCrypto(data) {
const bytes = CryptoJS.AES.decrypt(data, CryptoSecret);
const str = bytes.toString(CryptoJS.enc.Utf8);
if (str) return JSON.parse(str);
return null;
}