UNPKG

@izzius94/crypter

Version:

The crypter library makes easy to share encrypted data with a Laravel project.

34 lines (33 loc) 942 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.config = exports.read = exports.generate = void 0; const crypto_1 = require("crypto"); /** * Generate a new encryption key string encoded in base64 * * @param algorithm The algorithm that will be used to encrypt/decrypt the data * @returns The encryption key */ const generate = (algorithm = 'aes-256-cbc') => { return Buffer.from((0, crypto_1.randomBytes)(exports.config[algorithm])).toString('base64'); }; exports.generate = generate; /** * Read an encryption key from a base64 encoded string * * @param based The base64 enconded encryption key * @returns The buffer rappresenting the key */ const read = (based) => { return Buffer.from(based, 'base64'); }; exports.read = read; /** * The key length for each algorithm */ exports.config = { 'aes-128-cbc': 16, 'aes-256-cbc': 32, 'aes-256-gcm': 32, 'aes-128-gcm': 16 };