import { isNull } from "../base/isNull";
import CryptoJS from 'crypto-js';
/**
 * aes加密字符串，用于npv
 * @param str 待加密的字符串
 * @function aesEncryption
 * @access private
 */

var aesEncryption = function aesEncryption(str) {
  if (isNull(str)) {
    console.error('input is invalid');
    return null;
  } // 加密密钥


  var key = 'UITN25LMUQC436AH';
  var plaintkey = CryptoJS.enc.Utf8.parse(key);
  return CryptoJS.AES.encrypt(str, plaintkey, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  }).toString();
};
/**
 * ---
 * 字符串加密<br/>
 * * 'ASC' 加密   当前只有一种加密  后续会增加
 * @param {string} string 需要加密的字符
 * @param {string} [type="ASC"]  加密类型
 * @returns {null} 加密后的字符串
 * @function encryption
 * @static
 * @example 01 asc 加密
 * --------------------------------------------------------------------------
 * import {encryption} from '@riil-frontend/utils';
 * let string = 'riil猎豹';
 * encryption(string);
 * // result
 * "uoLPE3xmBdjHLXMudacZAg=="
 *
 */


export var encryption = function encryption(string) {
  var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'ASC';

  if (type === 'ASC') {
    return aesEncryption(string);
  }

  return string;
};