"use strict";
cc._RF.push(module, '771a32aQBNGVKd3+66gyTKA', 'HttpUtil');
// Script/module/Crypto/HttpUtil.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var CryptoJS = require("./crypto-js.min.js"); //引用AES源码js
var BASE_URL = "https://api.sparkus.cn";
//只负责网络接口 次类只负责和后端交互，不负责处理数据 数据处理在GameTool
var HttpUtil = /** @class */ (function (_super) {
    __extends(HttpUtil, _super);
    function HttpUtil() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    HttpUtil = __decorate([
        ccclass
    ], HttpUtil);
    return HttpUtil;
}(cc.Component));
exports.default = HttpUtil;
// 响应拦截器
// Rq.interceptors.response.use(responseHandler)
var config = {
    gameId: "100012",
    secretKey: "onnfPKJW",
    EK: "hui231%1"
};
var Crypoto = /** @class */ (function () {
    function Crypoto() {
        // 加密的向明值，自己根据项目实际情况定，需要跟后端开发保持一致
        this.keyHex = this.getHetKey();
    }
    Crypoto.prototype.getHetKey = function () {
        return CryptoJS.enc.Utf8.parse(config.EK);
    };
    /** DES加密 */
    Crypoto.prototype.encryptByDES = function (message, secret) {
        if (!message) {
            return message;
        }
        var key = secret ? CryptoJS.enc.Utf8.parse(secret) : this.keyHex;
        var encrypted = CryptoJS.DES.encrypt(message, key, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        return encrypted.toString();
    };
    /** DES解密 */
    Crypoto.prototype.decryptByDES = function (message, secret) {
        var key = secret ? CryptoJS.enc.Utf8.parse(secret) : this.keyHex;
        var decrypted = CryptoJS.DES.decrypt({
            ciphertext: CryptoJS.enc.Base64.parse(message)
        }, key, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        return decrypted.toString(CryptoJS.enc.Utf8);
    };
    /** hmacSHA256加密 */
    Crypoto.prototype.hmacSha256 = function (message, secret) {
        var keyHex = secret ? CryptoJS.enc.Utf8.parse(secret) : this.keyHex;
        var hash = CryptoJS.HmacSHA256(message, keyHex);
        return hash.toString();
    };
    /** hmacSHA256验证 */
    Crypoto.prototype.verifyHmacSha256 = function (message, signature) {
        var hash = CryptoJS.HmacSHA256(message, this.keyHex);
        return hash.toString() === signature;
    };
    /** CBC加密 */
    Crypoto.prototype.encryptCBC = function (word) {
        if (!word) {
            return word;
        }
        var srcs = CryptoJS.enc.Utf8.parse(word);
        var encrypted = CryptoJS.AES.encrypt(srcs, this.keyHex, {
            iv: this.keyHex,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.ZeroPadding
        });
        return encrypted.toString();
    };
    /** CBC解密 */
    Crypoto.prototype.decryptCBC = function (word) {
        if (!word) {
            return word;
        }
        var encryptedHexStr = CryptoJS.enc.Hex.parse(word);
        var srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
        var decrypt = CryptoJS.AES.decrypt(srcs, this.keyHex, {
            iv: this.keyHex,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.ZeroPadding
        });
        var decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
        return decryptedStr.toString();
    };
    return Crypoto;
}());
var fxCry = new Crypoto();

cc._RF.pop();