A simple encryption/decryption manager for storing sensitive data using the Node.JS crypto
module.
npm install cryptmanager
yarn add cryptmanager
pnpm add cryptmanager
import createCryptManager from 'cryptmanager';
const cryptManager = createCryptManager();
const encryptedString = await cryptManager.encryptString('Hello World'); // Output: base64 string
const decryptedString = await cryptManager.decryptString(encryptedString); // Output: Hello World
const buffer = Buffer.from(fs.readFileSync('./test.txt'));
const encryptedBuffer = await cryptManager.encrypt(buffer);
const decryptedBuffer = await cryptManager.decrypt(encryptedBuffer);
const myObject = {
hello: 'world',
};
const objectBuffer = Buffer.from(JSON.stringify(myObject));
const encryptedJSON = await cryptManager.encrypt(objectBuffer); // Output: Buffer
const decryptedBuffer = await cryptManager.decrypt(encryptedJSON);
const decryptedObject = JSON.parse(decryptedBuffer.toString('utf8')); // Output: Object