
Security Fundamentals
Turtles, Clams, and Cyber Threat Actors: Shell Usage
The Socket Threat Research Team uncovers how threat actors weaponize shell techniques across npm, PyPI, and Go ecosystems to maintain persistence and exfiltrate data.
The md5-hex npm package is a utility for generating MD5 hashes from strings or buffers. It is a simple and efficient way to create MD5 hashes, which are commonly used for checksums, data integrity verification, and other cryptographic purposes.
Generate MD5 hash from a string
This feature allows you to generate an MD5 hash from a given string. The code sample demonstrates how to import the md5-hex package and generate a hash for the string 'hello world'.
const md5Hex = require('md5-hex');
const hash = md5Hex('hello world');
console.log(hash); // Outputs: 5eb63bbbe01eeed093cb22bb8f5acdc3
Generate MD5 hash from a buffer
This feature allows you to generate an MD5 hash from a buffer. The code sample shows how to create a buffer from the string 'hello world' and then generate its MD5 hash.
const md5Hex = require('md5-hex');
const buffer = Buffer.from('hello world');
const hash = md5Hex(buffer);
console.log(hash); // Outputs: 5eb63bbbe01eeed093cb22bb8f5acdc3
The 'crypto' module is a built-in Node.js module that provides cryptographic functionality, including a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions. It is more comprehensive than md5-hex and supports various hashing algorithms, including MD5.
The 'md5' npm package is another utility for generating MD5 hashes. It is similar to md5-hex but offers a slightly different API. It can be used to hash strings, buffers, and even streams.
The 'hasha' npm package is a versatile hashing utility that supports multiple algorithms, including MD5, SHA-1, SHA-256, and more. It provides a simple API for hashing strings, buffers, and files, making it more flexible than md5-hex.
Create a MD5 hash with hex encoding
Please don't use MD5 hashes for anything sensitive!
Works in the browser too, when used with a bundler (like Webpack, Rollup, Browserify).
Checkout hasha
if you need something more flexible.
npm install md5-hex
import fs from 'node:fs';
import md5Hex from 'md5-hex';
const buffer = fs.readFileSync('unicorn.png');
md5Hex(buffer);
//=> '1abcb33beeb811dca15f0ac3e47b88d9'
Type: Buffer | string | Array<Buffer | string>
Prefer buffers as they're faster to hash, but strings can be useful for small things.
Pass an array instead of concatenating strings and/or buffers. The output is the same, but arrays do not incur the overhead of concatenation.
FAQs
Create a MD5 hash with hex encoding
We found that md5-hex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security Fundamentals
The Socket Threat Research Team uncovers how threat actors weaponize shell techniques across npm, PyPI, and Go ecosystems to maintain persistence and exfiltrate data.
Security News
At VulnCon 2025, NIST scrapped its NVD consortium plans, admitted it can't keep up with CVEs, and outlined automation efforts amid a mounting backlog.
Product
We redesigned our GitHub PR comments to deliver clear, actionable security insights without adding noise to your workflow.