"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CryptoUtils = void 0;
var crypto = require("crypto");
var CryptoJS = require('crypto-js');
var iconv = require("iconv-lite");
/**
 * 加密工具
 * @date 2020-09-17 10:34:52
 * @author 吴锋霖
 */
var CryptoUtils = /** @class */ (function () {
    function CryptoUtils() {
    }
    /**
     * MD5
     */
    CryptoUtils.md5 = function (txt) {
        var hash = crypto.createHash('md5');
        hash.update(txt);
        return hash.digest('hex');
    };
    /**
     * SHA256
     */
    CryptoUtils.sha256 = function (txt) {
        var hash = crypto.createHash('sha256');
        hash.update(txt);
        return hash.digest('hex');
    };
    //字符串非空判断
    CryptoUtils.isEmpty = function (txt) {
        if (txt == null || txt == '' || txt == undefined) {
            return true;
        }
        else {
            return false;
        }
    };
    /**
     * SHA256
     */
    CryptoUtils.sha1 = function (txt) {
        var hash = crypto.createHash('sha1');
        hash.update(txt);
        return hash.digest('hex');
    };
    /**
     * Base64编码
     * @param txt
     */
    CryptoUtils.base64Encode = function (txt) {
        return Buffer.from(txt).toString('base64');
    };
    /**
     * Base64解码
     * @param base64String
     * @param encoding
     */
    CryptoUtils.base64Decode = function (base64String, encoding) {
        if (encoding === void 0) { encoding = 'utf8'; }
        return Buffer.from(base64String, 'base64').toString(encoding);
    };
    /**
    * 3des加密
    * @param base64String
    * @param encoding
    */
    CryptoUtils.des3Encrypt = function (txt, type, key, iv, encoding) {
        if (type === void 0) { type = 'des-ede3-cbc'; }
        if (key === void 0) { key = ''; }
        if (iv === void 0) { iv = ''; }
        if (encoding === void 0) { encoding = 'GB2312'; }
        var keyDes = Buffer.from(key);
        var ivDes = Buffer.from((iv ? iv : ""));
        var cipher = crypto.createCipheriv(type, keyDes, ivDes);
        var ciph_1 = cipher.update(iconv.encode(txt, encoding));
        var ciph_2 = cipher.final();
        var res = Buffer.concat([ciph_1, ciph_2]).toString('base64');
        return res;
    };
    CryptoUtils.des3DecryCode = function (data, key, iv) {
        var decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv);
        var decrypted = decipher.update(data, 'base64', 'utf8');
        decrypted += decipher.final('utf8');
        return decrypted;
    };
    return CryptoUtils;
}());
exports.CryptoUtils = CryptoUtils;
//# sourceMappingURL=CryptoUtils.js.map