Skip to content

jsdev-robin/node-encryptor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 scrypt key derivation.
  • Asymmetric Encryption: RSA key pair generation and encryption/decryption.
  • Hashing & HMAC: SHA-256 based utilities for data integrity.
  • Security First: Uses timingSafeEqual for 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;
}

Releases

No releases published

Packages

 
 
 

Contributors