@toolsnap/hash-generator-tool
v1.0.0
Published
A universal hash generator supporting MD5, SHA1, SHA256, SHA512 and more for strings, files, and buffers
Downloads
74
Maintainers
Readme
@toolsnap/hash-generator-tool
A universal hash generator supporting MD5, SHA1, SHA256, SHA512, and more — for strings, files, and buffers.
Features
- Multiple Algorithms — MD5, SHA1, SHA256, SHA384, SHA512
- String Hashing — Generate hashes from any string or text input
- File Hashing — Compute checksums for files on disk
- Buffer Support — Hash raw binary data directly
- Streaming — Hash large files efficiently with streaming API
- HMAC Support — Generate HMAC signatures with a secret key
- Built on Node.js Crypto — Native performance, no external dependencies
Installation
npm install @toolsnap/hash-generator-toolUsage
Hash a String
const { hash } = require('@toolsnap/hash-generator-tool');
// SHA-256 (default)
console.log(hash('hello world'));
// b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
// Specify algorithm
console.log(hash('hello world', 'md5'));
// 5eb63bbbe01eeed093cb22bb8f5acdc3
console.log(hash('hello world', 'sha1'));
// 2aae6c35c94fcfb415dbe95f408b9ce91ee846edHash a File
const { hashFile } = require('@toolsnap/hash-generator-tool');
async function checksum() {
const sha256 = await hashFile('./package.json', 'sha256');
console.log(sha256);
}HMAC Signature
const { hmac } = require('@toolsnap/hash-generator-tool');
console.log(hmac('hello world', 'my-secret-key', 'sha256'));
// e.g. a3f2b8c1d4e5...Supported Algorithms
| Algorithm | Output Length | Use Case | |-----------|-------------|----------| | MD5 | 32 hex chars | Legacy checksums, non-security | | SHA1 | 40 hex chars | Git commits, legacy signatures | | SHA256 | 64 hex chars | General purpose, recommended default | | SHA384 | 96 hex chars | Higher security requirements | | SHA512 | 128 hex chars | Maximum security, large data |
Use Cases
- File Integrity Verification — Generate and compare checksums to verify file integrity after download or transfer
- Password Hashing — Store password hashes instead of plaintext (use with salt for production)
- API Authentication — Sign API requests with HMAC for secure communication
- Data Deduplication — Identify duplicate content by comparing hash values
- Change Detection — Monitor file changes by tracking hash differences
Best Practices
- Use SHA-256 or higher for security-sensitive applications — MD5 and SHA1 have known collision vulnerabilities
- Always use HMAC with a secret key for API signatures — Plain hashes can be forged
- Salt passwords before hashing — Add random data to prevent rainbow table attacks
- Verify file hashes after downloads — Ensure downloaded files haven't been tampered with
- Choose algorithm based on threat model — SHA512 for high-security, SHA256 for general use
License
MIT
Try our free online tools at RiseTop
