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.
- 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.
npm install node-encryptorimport { 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;
}