/**
 * lib/aes
 *
 * @see https://github.com/keel/aes-cross/tree/master/info-cn
 */
import crypto from 'crypto';
var algorithm = 'aes-256-cbc';
var aes = {
    process: function (data, key, type) {
        if (type === void 0) { type = 'encryption'; }
        var keyBuf = new Buffer(Array(32));
        var ivBuf = new Buffer(Array(16));
        var result = data;
        keyBuf.write(key);
        var cipher = type === 'encryption'
            ? crypto.createCipheriv(algorithm, keyBuf, ivBuf)
            : crypto.createDecipheriv(algorithm, keyBuf, ivBuf);
        cipher.setAutoPadding(true);
        if (!Buffer.isBuffer(data)) {
            result = new Buffer(result);
        }
        var buf = Buffer.concat([
            cipher.update(result),
            cipher.final(),
        ]);
        return buf;
    },
    encryption: function (data, key) {
        return this.process(data, key, 'encryption');
    },
    decryption: function (data, key) {
        return this.process(data, key, 'decryption');
    },
};
export default aes;
