import CryptoJS from 'crypto-js';

// //秘钥

const CRYPTOJSKEY = '81eba4f68353e6d5';
/**
 * 加密
 * @param word
 * @returns {*}
 */
export function encrypt(word: any) {
    let key = CryptoJS.enc.Utf8.parse(CRYPTOJSKEY);
    let srcs = CryptoJS.enc.Utf8.parse(word);
    let encrypted = CryptoJS.AES.encrypt(srcs, key, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7,
    });
    return encrypted.toString();
}

/**
 * 解密
 * @param word
 * @returns {*}
 */
export function decrypt(word: any) {
    let key = CryptoJS.enc.Utf8.parse(CRYPTOJSKEY);
    let decrypt = CryptoJS.AES.decrypt(word, key, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7,
    });
    return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}
