"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.encryption = void 0;

var _isNull = require("../base/isNull");

var _cryptoJs = _interopRequireDefault(require("crypto-js"));

/**
 * aes加密字符串，用于npv
 * @param str 待加密的字符串
 * @function aesEncryption
 * @access private
 */
var aesEncryption = function aesEncryption(str) {
  if ((0, _isNull.isNull)(str)) {
    console.error('input is invalid');
    return null;
  } // 加密密钥


  var key = 'UITN25LMUQC436AH';

  var plaintkey = _cryptoJs.default.enc.Utf8.parse(key);

  return _cryptoJs.default.AES.encrypt(str, plaintkey, {
    mode: _cryptoJs.default.mode.ECB,
    padding: _cryptoJs.default.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=="
 *
 */


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

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

  return string;
};

exports.encryption = encryption;