"use strict";
/*
 * ATTENTION: An "eval-source-map" devtool has been used.
 * This devtool is neither made for production nor for readable output files.
 * It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 * or disable the default devtool with "devtool: false".
 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 */
(self["webpackChunknocode_platform"] = self["webpackChunknocode_platform"] || []).push([[8956],{

/***/ "./src/utils/crypto.ts":
/*!*****************************!*\
  !*** ./src/utils/crypto.ts ***!
  \*****************************/
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {

eval("\n\nvar _Object$defineProperty = __webpack_require__(/*! @babel/runtime-corejs3/core-js-stable/object/define-property */ \"../../node_modules/@babel/runtime-corejs3/core-js-stable/object/define-property.js\");\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime-corejs3/helpers/interopRequireDefault */ \"../../node_modules/@babel/runtime-corejs3/helpers/interopRequireDefault.js\");\n_Object$defineProperty(exports, \"__esModule\", {\n  value: true\n});\nexports.encryptByBase64 = exports.encrypt = exports.decryptByBase64 = exports.decrypt = exports.KEY = exports.IV = void 0;\nexports.encryptUserActionData = encryptUserActionData;\nexports.getEncodeValue = exports.getDecodeValue = void 0;\nvar _stringify = _interopRequireDefault(__webpack_require__(/*! @babel/runtime-corejs3/core-js-stable/json/stringify */ \"../../node_modules/@babel/runtime-corejs3/core-js-stable/json/stringify.js\"));\nvar _promise = _interopRequireDefault(__webpack_require__(/*! @babel/runtime-corejs3/core-js-stable/promise */ \"../../node_modules/@babel/runtime-corejs3/core-js-stable/promise.js\"));\nvar _concat = _interopRequireDefault(__webpack_require__(/*! @babel/runtime-corejs3/core-js-stable/instance/concat */ \"../../node_modules/@babel/runtime-corejs3/core-js-stable/instance/concat.js\"));\nvar _cryptoJs = _interopRequireDefault(__webpack_require__(/*! kd_libs/crypto-js */ \"webpack/container/remote/kd_libs/crypto-js\"));\n/*\n * @Description:\n * @Author: jianhang_he\n * @Date: 2023-06-26 10:39:12\n * @LastEditTime: 2023-06-26 10:39:58\n * @Last Modified by: jianhang_he\n */\n/**\n * 传输内容加密\n * npm install crypto-js\n */\n\n// import sha256 from 'crypto-js/sha256'\n// import { List, Map } from 'immutable'\n\nvar ALGONAME = 'AES'; // 加密算法\nvar KEY = exports.KEY = '091A126D76A4B595'; // 十六位十六进制的密钥，与后端约定好的\nvar IV = exports.IV = 'B5EFEB5E3226D81A'; // 十六位十六进制的偏移量，与后端约定好的\n\n// 加密是字符串,对象\\数组暂不支持\n// key十六位十六进制数作为密钥\n// iv十六位十六进制数作为偏移量\nvar encrypt = exports.encrypt = function encrypt(data, key, iv) {\n  key = _cryptoJs.default.enc.Utf8.parse(key);\n  iv = _cryptoJs.default.enc.Utf8.parse(iv);\n  // data = typeof data === \"object\" ? JSON.stringify(data) : data\n  data = _cryptoJs.default.enc.Utf8.parse(data);\n  var cfg = {\n    iv: iv,\n    mode: _cryptoJs.default.mode.CBC,\n    padding: _cryptoJs.default.pad.Pkcs7\n  };\n  var encrypted = _cryptoJs.default[ALGONAME].encrypt(data, key, cfg);\n  var decryptedStr = encrypted.ciphertext.toString().toUpperCase();\n  var hexStr = _cryptoJs.default.enc.Hex.parse(decryptedStr);\n  var base64Str = _cryptoJs.default.enc.Base64.stringify(hexStr);\n  return base64Str;\n};\n\n// 解密data 是字符串, 仅测试使用，前端不需要提供解密\nvar decrypt = exports.decrypt = function decrypt(data, key, iv) {\n  key = _cryptoJs.default.enc.Utf8.parse(key);\n  iv = _cryptoJs.default.enc.Utf8.parse(iv);\n  var cfg = {\n    iv: iv,\n    mode: _cryptoJs.default.mode.CBC,\n    padding: _cryptoJs.default.pad.Pkcs7\n  };\n  var decrypt = _cryptoJs.default[ALGONAME].decrypt(data, key, cfg);\n  var decryptedStr = decrypt.toString(_cryptoJs.default.enc.Utf8);\n  // decryptedStr = isObject ? JSON.parse(decryptedStr) : decryptedStr\n  var value = decryptedStr.toString();\n  return value;\n};\nvar getDecodeValue = exports.getDecodeValue = function getDecodeValue(value) {\n  if (!value) return value;\n  return decrypt(value, KEY, IV);\n};\nvar getEncodeValue = exports.getEncodeValue = function getEncodeValue(value) {\n  if (!value) return value;\n  return encrypt(value, KEY, IV);\n};\n\n// base64编码\nvar encryptByBase64 = exports.encryptByBase64 = function encryptByBase64(value) {\n  var valueStr = value;\n  if (Array.isArray(valueStr) || Object.prototype.toString.call(valueStr) === '[object Object]') {\n    valueStr = (0, _stringify.default)(valueStr);\n  }\n  var wordArray = _cryptoJs.default.enc.Utf8.parse(valueStr);\n  var base64Str = _cryptoJs.default.enc.Base64.stringify(wordArray);\n  return base64Str;\n};\n\n// base64解码\nvar decryptByBase64 = exports.decryptByBase64 = function decryptByBase64(value) {\n  var parsedWordArray = _cryptoJs.default.enc.Base64.parse(value);\n  var parsedStr = parsedWordArray.toString(_cryptoJs.default.enc.Utf8);\n  return parsedStr;\n};\n\n/**\n * 生成埋点数据签名\n * @des project 项目名\n * @des store 仓库名\n * @des time 时间戳\n * @des nonce 唯一标识\n * @des ce 加密码\n * @returns Promise\n */\nfunction encryptUserActionData(data) {\n  return new _promise.default(function (resolve, reject) {\n    try {\n      var _context, _context2, _context3;\n      var _ref = data || {},\n        time = _ref.time,\n        nonce = _ref.nonce,\n        ce = _ref.ce,\n        project = _ref.project,\n        store = _ref.store;\n      var srcStr = (0, _concat.default)(_context = (0, _concat.default)(_context2 = (0, _concat.default)(_context3 = \"POST\\n%2Fladdercs%2Fladderlog\\nproject=\".concat(project, \"&store=\")).call(_context3, store, \"\\nx-api-nonce:\")).call(_context2, nonce, \"\\nx-api-timestamp:\")).call(_context, time, \"\\n\");\n      var sha256 = _cryptoJs.default.HmacSHA256(srcStr, ce); // hmac sha256加密\n      var hex = _cryptoJs.default.enc.Hex.stringify(sha256); // 转16进制\n      var signature = _cryptoJs.default.enc.Base64.stringify(_cryptoJs.default.enc.Utf8.parse(hex)); // 转base64\n      resolve({\n        nonce: nonce,\n        encrypt: signature\n      });\n    } catch (error) {\n      reject(error);\n    }\n  });\n}//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64, \n//# sourceURL=webpack-internal:///./src/utils/crypto.ts\n");

/***/ })

}]);