"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var crypto_js_1 = require("crypto-js");
var core_1 = require("../../core");
var AesEcb128Converter = /** @class */ (function () {
    // _cipher?: Cipher;
    // _decipher?: Decipher;
    function AesEcb128Converter(options) {
        if (options) {
            this.setOptions(options);
        }
    }
    AesEcb128Converter.prototype.setOptions = function (value) {
        this._options = value;
        // this._cipher = createCipheriv(AesEcb128Converter.ALGO, Buffer.from(this._options.key.buffer), this._options.iv);
        // this._decipher = createDecipheriv(AesEcb128Converter.ALGO, Buffer.from(this._options.key.buffer), this._options.iv);
        // this._decipher.setAutoPadding(false); // Mandatory apparently otherwise result is null...
    };
    Object.defineProperty(AesEcb128Converter.prototype, "options", {
        get: function () {
            return this._options;
        },
        enumerable: true,
        configurable: true
    });
    AesEcb128Converter.prototype.encode = function (data) {
        if (!this._options) {
            throw new Error("AES options has not been set yet");
        }
        var input = crypto_js_1.enc.Hex.parse(core_1.FormatHelper.toHexString(data));
        var key = crypto_js_1.enc.Hex.parse(this._options.key);
        var iv = crypto_js_1.enc.Hex.parse(this._options.iv);
        var encrypted = crypto_js_1.AES.encrypt(input, key, {
            iv: iv,
            mode: crypto_js_1.mode.CBC,
            padding: crypto_js_1.pad.NoPadding
        });
        var encryptedHexString = crypto_js_1.enc.Hex.stringify(encrypted.ciphertext);
        return core_1.FormatHelper.hexStringToBuffer(encryptedHexString);
    };
    AesEcb128Converter.prototype.decode = function (data) {
        if (!this._options) {
            throw new Error("AES options has not been set yet");
        }
        var input = crypto_js_1.enc.Hex.parse(core_1.FormatHelper.toHexString(data));
        var key = crypto_js_1.enc.Hex.parse(this._options.key);
        var iv = crypto_js_1.enc.Hex.parse(this._options.iv);
        var decrypted = crypto_js_1.AES.decrypt({
            ciphertext: input,
            salt: "",
            iv: iv,
        }, key, {
            iv: iv,
            mode: crypto_js_1.mode.CBC,
            padding: crypto_js_1.pad.NoPadding
        });
        return core_1.FormatHelper.hexStringToBuffer(decrypted.toString(crypto_js_1.enc.Hex));
    };
    return AesEcb128Converter;
}());
exports.AesEcb128Converter = AesEcb128Converter;
