UNPKG

@nestia/fetcher

Version:

Fetcher library of Nestia SDK

49 lines 1.6 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AesPkcs5 = void 0; var crypto_1 = __importDefault(require("crypto")); /** * Utility class for the AES-128/256 encryption. * * - AES-128/256 * - CBC mode * - PKCS#5 Padding * - Base64 Encoding * * @author Jeongho Nam - https://github.com/samchon */ var AesPkcs5; (function (AesPkcs5) { /** * Encrypt data * * @param data Target data * @param key Key value of the encryption. * @param iv Initializer Vector for the encryption * @returns Encrypted data */ function encrypt(data, key, iv) { var bytes = key.length * 8; var cipher = crypto_1.default.createCipheriv("AES-".concat(bytes, "-CBC"), key, iv); return cipher.update(data, "utf8", "base64") + cipher.final("base64"); } AesPkcs5.encrypt = encrypt; /** * Decrypt data. * * @param data Target data * @param key Key value of the decryption. * @param iv Initializer Vector for the decryption * @returns Decrypted data. */ function decrypt(data, key, iv) { var bytes = key.length * 8; var decipher = crypto_1.default.createDecipheriv("AES-".concat(bytes, "-CBC"), key, iv); return decipher.update(data, "base64", "utf8") + decipher.final("utf8"); } AesPkcs5.decrypt = decrypt; })(AesPkcs5 || (exports.AesPkcs5 = AesPkcs5 = {})); //# sourceMappingURL=AesPkcs5.js.map