Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (21 sloc) 760 Bytes
layout title date excerpt categories
post
Create MD5 hash with Node.js
2017-04-20 23:45:00 -4000
How to calculate an MD5 hash of a string with Node.js.
nodejs md5 hash

Given a string:

var string = 'my string';

You can generate an MD5 hash like so:

var crypto = require('crypto');
var hash = crypto.createHash('md5').update(string).digest('hex');
console.log(hash);

As a reminder, you probably don't want to use the MD5 algorithm for encryption as it can be easily brute-forced.

However, it does serve as a useful checksum to verify data integrity.

Here's a module that calculates MD5 hashes:

{% gist ef52f3fb1c16cf7aaf8aae1fc81aceca %}