UNPKG

@nestia/fetcher

Version:

Fetcher library of Nestia SDK

47 lines (44 loc) 1.3 kB
import crypto from '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) { const bytes = key.length * 8; const cipher = crypto.createCipheriv(`AES-${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) { const bytes = key.length * 8; const decipher = crypto.createDecipheriv(`AES-${bytes}-CBC`, key, iv); return decipher.update(data, "base64", "utf8") + decipher.final("utf8"); } AesPkcs5.decrypt = decrypt; })(AesPkcs5 || (AesPkcs5 = {})); export { AesPkcs5 }; //# sourceMappingURL=AesPkcs5.mjs.map