MD5 Hashing Utility

1.3.5 · maintenance · verified Sun Apr 19

The `md5.js` package provides an MD5 hashing algorithm implementation written purely in JavaScript, designed to be compatible with Node.js's `crypto` module style. As of its current stable version 1.3.5, it offers a straightforward API for computing MD5 hashes from strings or streams. While it facilitates MD5 computation, it's crucial for developers to acknowledge that the MD5 algorithm is cryptographically compromised, particularly regarding its collision resistance, as highlighted by NIST SP 800-131A. This vulnerability makes it unsuitable for security-sensitive applications such as digital signatures, password hashing, or any scenario where collision resistance is paramount. The package is part of the broader `crypto-browserify` project, which aims to provide Node.js-compatible cryptographic primitives for browser environments, often through polyfills. It maintains a stable, rather than rapid, release cadence, reflecting its mature and foundational utility, despite the inherent cryptographic weaknesses of MD5 itself. Its key differentiator is its pure JavaScript nature, making it universally deployable without native dependencies.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates both synchronous string hashing and asynchronous, stream-like processing to compute MD5 hashes, outputting them in hexadecimal format.

const MD5 = require('md5.js');

// Compute MD5 hash of a string
const inputString = 'hello world';
const hash1 = new MD5().update(inputString).digest('hex');
console.log(`MD5 of '${inputString}': ${hash1}`);
// Expected: 5d41402abc4b2a76b9719d911017c592

// Compute MD5 hash using stream-like interface
const md5Stream = new MD5();
md5Stream.write('some ');
md5Stream.write('more ');
md5Stream.end('data'); // Signal end of input
const hash2 = md5Stream.read().toString('hex');
console.log(`MD5 of 'some more data': ${hash2}`);
// Expected: e6b4d32e5b7c4d519b7d0187a55c26b8

view raw JSON →