import CryptoJS from 'crypto-js';
/**
 * Des密钥
 * 手机发送验证码时加密方法
 * @param mobile
 */
function encryptDesMobile(mobile: string): string {
    const key = "Ub$kl^P3";
    const message = CryptoJS.enc.Utf8.parse(mobile);
    const keyHex = CryptoJS.enc.Utf8.parse(key);
    const ivHex = CryptoJS.enc.Utf8.parse(key);
    const encrypted = CryptoJS.DES.encrypt(message, keyHex,{
        iv: ivHex,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });
    return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
}

/**
 * 获取加密后的手机号码
 * @param mobile 手机号码
 * @returns 加密后的手机号码
 */
export function getEncryptMobile(mobile: string) {
    let encryptMobile = encryptDesMobile(mobile)
    const reg1 = new RegExp('\\+','g'), reg2 = new RegExp('\/','g'), reg3 = new RegExp('\=','g');
    encryptMobile = encryptMobile.replace(reg1,'*');
    encryptMobile = encryptMobile.replace(reg2,'-');
    encryptMobile = encryptMobile.replace(reg3,'.');
    return encryptMobile
}
