0.0.1-alpha1 • Published 9 months ago
cryptmanager v0.0.1-alpha1
CryptManager
A simple encryption/decryption manager for storing sensitive data using the Node.JS crypto
module.
Installation
npm install cryptmanager
yarn add cryptmanager
pnpm add cryptmanager
Usage
import createCryptManager from 'cryptmanager';
const cryptManager = createCryptManager();
Encrypt/Decrypt a string
const encryptedString = await cryptManager.encryptString('Hello World'); // Output: base64 string
const decryptedString = await cryptManager.decryptString(encryptedString); // Output: Hello World
Encrypt/Decrypt a buffer object (e.g. a file)
const buffer = Buffer.from(fs.readFileSync('./test.txt'));
const encryptedBuffer = await cryptManager.encrypt(buffer);
const decryptedBuffer = await cryptManager.decrypt(encryptedBuffer);
Encrypt/Decrypt a JSON object
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
0.0.1-alpha1
9 months ago