@ts-utilkit/crypto
v0.2.0
Published
Cryptographic utilities for hashing (SHA-256, SHA-512, MD5), encryption (AES-256), HMAC, and password management
Maintainers
Readme
@ts-utilkit/crypto
Cryptographic utilities for hashing, encryption, HMAC, and secure password management using Node.js built-in crypto module.
Installation
npm install @ts-utilkit/cryptoFeatures
- 🔒 Secure cryptographic operations using Node.js crypto
- 🔐 Multiple hashing algorithms (SHA-256, SHA-512, MD5)
- 🛡️ AES-256-GCM encryption/decryption
- ✅ HMAC generation and verification
- 🔑 Secure password hashing with PBKDF2
- ⚡ Timing-safe comparisons to prevent timing attacks
- 📖 Comprehensive documentation and examples
Available Functions (11)
compareHash- Timing-safe hash comparisondecryptAES256- AES-256-GCM decryptionencryptAES256- AES-256-GCM encryptiongenerateHMAC- Generate HMAC for data integritygenerateRandomBytes- Generate secure random bytesgenerateSalt- Generate cryptographic salt (32 hex chars)hashMD5- MD5 hashing (legacy support only)hashPassword- Secure password hashing with PBKDF2hashSHA256- SHA-256 hashinghashSHA512- SHA-512 hashingverifyHMAC- Timing-safe HMAC verification
Quick Example
import {
hashPassword,
generateSalt,
encryptAES256,
generateHMAC,
} from '@ts-utilkit/crypto';
// Password hashing
const salt = generateSalt();
const hash = hashPassword('password123', salt);
// Encryption (requires 64-char hex key)
const encrypted = encryptAES256('secret', key);
// HMAC signatures
const signature = generateHMAC(data, secret, 'sha256');License
MIT © Mykyta Forofontov
