Douglas Moura

Douglas Moura

Software Engineer

Douglas Moura

Douglas Moura

Software Engineer, Musician and Jiujiteiro.

Generating MD5 hashes on Node.js

Published at:Published at:Updated at:

Generating MD5 hashes on Node.js

You can create hashes in Node.js without the need to install any external library. Usually, I create the following utility function in the projects I work on:

/**
 * Hashes a string using md5
 *
 * @param {string} str
 * @returns {string}
 */
export const md5 = (str) => createHash('md5').update(str).digest('hex')

And I use it to replace the md5 library whenever I come across it.

Note that you can create hashes for any algorithm supported by the OpenSSL version on your platform. On Linux and Mac, you can see which algorithms are available with the command openssl list -digest-algorithms.

Leave a Reply

Loading comments...