node-encryptor
v1.1.0
Published
A Node.js library providing encryption, decryption, hashing, HMAC, RSA, and secure utility functions for modern applications.
Maintainers
Readme
node-encryptor
A lightweight, production-ready Node.js utility library for modern cryptography. It provides a clean, promise-based API for symmetric encryption (AES), asymmetric encryption (RSA), hashing, HMAC, and secure comparisons.
🚀 Features
- Symmetric Encryption: AES-192-CBC with
scryptkey derivation. - Asymmetric Encryption: RSA key pair generation and encryption/decryption.
- Hashing & HMAC: SHA-256 based utilities for data integrity.
- Security First: Uses
timingSafeEqualfor comparisons and secure random byte generation. - TypeScript Native: Full type definitions included.
📦 Installation
npm install node-encryptor📦 Usage
import { Crypto } from 'node-encryptor';
// Symmetric Encryption
const encrypted = await Crypto.cipheriv(
{ message: 'Hello World' },
'my-password',
);
const decrypted = await Crypto.decipheriv(encrypted, 'my-password');
console.log(decrypted); // { message: 'Hello World' }
// Hashing
const hash = Crypto.hash('my data');
const hmac = Crypto.hmac('my data', 'secret-key');
// RSA Encryption
const { publicKey, privateKey } = Crypto.generateRSAKeyPair();
const encryptedRSA = Crypto.encryptWithPublicKey('secret message', publicKey);
const decryptedRSA = Crypto.decryptWithPrivateKey(encryptedRSA, privateKey);
// Utilities
const randomHex = Crypto.randomHexString(32);
const isEqual = Crypto.safeCompare('value1', 'value2');
// Interfaces
interface Decipheriv {
salt: string;
iv: string;
data: string;
}