npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ts-utilkit/crypto

v0.1.0

Published

Cryptographic utilities for hashing (SHA-256, SHA-512, MD5), encryption (AES-256), HMAC, and password management

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/crypto

Features

  • 🔒 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

Functions

Hashing

  • hashSHA256 - SHA-256 hashing
  • hashSHA512 - SHA-512 hashing
  • hashMD5 - MD5 hashing (legacy support only)
  • hashPassword - Secure password hashing with PBKDF2
  • compareHash - Timing-safe hash comparison

Encryption/Decryption

  • encryptAES256 - AES-256-GCM encryption
  • decryptAES256 - AES-256-GCM decryption

HMAC

  • generateHMAC - Generate HMAC for data integrity
  • verifyHMAC - Timing-safe HMAC verification

Utilities

  • generateSalt - Generate cryptographic salt (32 hex chars)
  • generateRandomBytes - Generate secure random bytes

Usage Examples

Password Hashing

import { hashPassword, generateSalt, compareHash } from '@ts-utilkit/crypto';

// Register user
const salt = generateSalt();
const hashedPassword = hashPassword('userPassword123', salt);
// Store: { salt, hashedPassword } in database

// Login verification
const loginHash = hashPassword(inputPassword, storedSalt);
const isValid = compareHash(loginHash, storedHashedPassword);

Data Hashing

import { hashSHA256, hashSHA512 } from '@ts-utilkit/crypto';

// Hash data
const hash256 = hashSHA256('sensitive data');
const hash512 = hashSHA512('sensitive data');

// Hash file content
const fileContent = fs.readFileSync('document.pdf');
const fileHash = hashSHA256(fileContent);

Encryption/Decryption

import { encryptAES256, decryptAES256 } from '@ts-utilkit/crypto';

// Generate a 256-bit key (64 hex characters)
const key = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';

// Encrypt sensitive data
const encrypted = encryptAES256('Secret message', key);
// Result includes IV and auth tag: "iv:authTag:encryptedData"

// Decrypt data
const decrypted = decryptAES256(encrypted, key);
// Result: "Secret message"

HMAC for API Signatures

import { generateHMAC, verifyHMAC } from '@ts-utilkit/crypto';

// Client: Sign API request
const secretKey = 'shared-secret-key';
const requestData = JSON.stringify({ user: 'alice', action: 'transfer' });
const signature = generateHMAC(requestData, secretKey, 'sha256');

// Send: { data: requestData, signature }

// Server: Verify signature
const isValid = verifyHMAC(
  receivedData,
  receivedSignature,
  secretKey,
  'sha256'
);

if (isValid) {
  // Process request
} else {
  // Reject - data was tampered with
}

Generate Random Data

import { generateSalt, generateRandomBytes } from '@ts-utilkit/crypto';

// Generate salt for password hashing
const salt = generateSalt();
// Result: 32 hex characters

// Generate random bytes
const randomHex = generateRandomBytes(16);
// Result: 32 hex characters (16 bytes)

Security Notes

⚠️ Important Guidelines

  1. Never use MD5 for security - Only for legacy compatibility
  2. Use SHA-256 or SHA-512 for hashing
  3. Store passwords with PBKDF2 (hashPassword function)
  4. Use timing-safe comparisons (compareHash, verifyHMAC)
  5. Generate strong keys - Use cryptographically secure random values
  6. Protect your keys - Never commit keys to version control
  7. AES-256-GCM provides authenticated encryption (prevents tampering)

Algorithm Support

Hashing: sha256, sha512, md5
HMAC: sha256, sha512, sha1, md5
Encryption: AES-256-GCM (most secure AES mode)

API Documentation

All functions include:

  • Strict input validation
  • Descriptive error messages
  • Timing-attack resistance where applicable
  • Complete TypeScript types
  • Comprehensive examples

For detailed API documentation, visit the main repository.

License

MIT © MForofontov