"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var mslib_1 = require("mslib");
var CryptoJS = require('crypto-js');
var dayjs = require("dayjs");
/**
 *
 * @date 2021-07-16 14:04:33
 * @author 林颖
 */
var StcLotIdUtils = /** @class */ (function () {
    function StcLotIdUtils() {
    }
    /**
     * lotId加密
     */
    StcLotIdUtils.prototype.lotIdEncrypt = function (lotId) {
        var ciphertext = lotId;
        var key = CryptoJS.enc.Utf8.parse(dayjs().format('YYYYMMDDYYYYMMDD'));
        var iv = CryptoJS.enc.Hex.parse('00000000');
        var options = {
            iv: iv,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        };
        ciphertext = CryptoJS.AES.encrypt(lotId, key, options).toString();
        mslib_1.logger.info("lotId:%s AES加密出来的密文----%s", lotId, ciphertext);
        return ciphertext;
    };
    /**
     * lotId解密
     */
    StcLotIdUtils.prototype.lotIdDecrypt = function (ciphertext) {
        var lotId = ciphertext;
        var key = CryptoJS.enc.Utf8.parse(dayjs().format('YYYYMMDDYYYYMMDD'));
        var iv = CryptoJS.enc.Hex.parse('00000000');
        var options = {
            iv: iv,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        };
        ciphertext = ciphertext.replace(/=/g, "").replace(/\-/g, "+").replace(/_/g, "/"); // 转换为字符串
        lotId = CryptoJS.AES.decrypt(ciphertext, key, options).toString(CryptoJS.enc.Utf8);
        mslib_1.logger.info("ciphertext:%s AES解密出来的明文----%s", ciphertext, lotId);
        return lotId;
    };
    return StcLotIdUtils;
}());
exports.StcLotIdUtils = StcLotIdUtils;
//# sourceMappingURL=StcLotIdUtils.js.map