How to use MD5 hashes in JavaScript

In this article, you are going learn to use the MD5 hashes in JavaScript. The MD5 hash function was originally created as a secure cryptographic algorithm to authenticate digital signatures.

However, it has since been deprecated for such purposes due to its vulnerabilities.

Instead, it is commonly used for non-cryptographic checksums to check data integrity and identify unintended data corruption. This means that it is frequently employed to ensure the integrity of files.

Although JavaScript lacks built-in cryptographic utilities, the same functionality can be obtained by implementing third-party libraries.

What is JavaScript MD5?

This JavaScript MD5 is designed to work smoothly in different server-side environments such as Node.js, module loaders like RequireJS or webpack, and across all web browsers.

How to add MD5 to your Project?

When your project needs a package manager, you can simply install it using NPM through the following command:

npm install blueimp-md5

If you come from the old school, simply add the MD5 script to your document through including the original or shortened version from the official repository (available here).

Here’s an example code:

<!-- Include MD5 library -->
<script src="md5.js"></script>

<!-- Include MD5 minified version -->
<script src="md5.min.js"></script>

To get further details regarding this library, kindly visit its official GitHub repository by clicking here.

How to hash using the MD5

To start with, make sure you have already installed the MD5 library in your project. If it’s already installed, the next step is to import it.

For Example:

// When you are using a package manager that require the package
const md5 = require("blueimp-md5");

// When you are using ES6
import { md5 } from "blueimp-md5";

Once it is already importing it, its usage will be quite simple. md5 is a function that takes up to 3 parameters:

  • value (string)
    • This is the input value that will be hashed using the MD5 algorithm.
  • key (string)
    • If you need to use the HMAC to key-hash a string, provide it as the second argument.
  • raw (Boolean)
    • This Boolean defines whether the hash should be in raw or hex encoded format (false by default).

Using MD5 hash

You can simply make the MD5 hash of a given string through providing it as first argument:

Let’s see an example code:


let hash = md5("password");

// contains: "5f4dcc3b5aa765d61d8327deb882cf99"

Using HMAC-MD5

You can simply build the HMAC-MD5 hash of given string by providing as first argument its value and as second argument its key:

For example:

let hash = md5("passoword", "itsourcecode");

Utilizing Raw MD5 hash

You can easily generate the raw MD5 hash of a given string by providing it as the first argument, setting the second argument to null, and the third argument to true.

Here’s an example:

let rawhash = md5("password", null, true);

Utilizing Raw HMAC-MD5

You can simply generate the raw HMAC-MD5 hash for a given string by providing the string as the first argument, the key as the second argument, and setting the third parameter to true.

Example that uses the Raw HMAC-MD5 :

let rawhash = md5('password', 'itsourcecode', true)

Conclusion

In conclusion, you have learned how to use MD5 hashes in JavaScript, what is the meaning of JavaScript MD5.

Also, we have discussed how to add MD5 to your project and how to hash using the MD5.

Additional Resources

Frequently Asked Questions

Is JavaScript still worth learning in 2026?
Yes. JavaScript runs on 98% of websites for the front-end, dominates the back-end via Node.js, powers mobile apps through React Native, builds desktop tools through Electron, and is the scripting layer for most AI tooling (LangChain.js, OpenAI SDK, Vercel AI). Whether you target web, mobile, AI, or full-stack capstones, JavaScript is the broadest single language you can learn.
What is the difference between var, let, and const?
var is function-scoped, hoisted to the top of its scope, and can be redeclared, which leads to bugs in modern code. let is block-scoped (only visible inside the nearest {}) and can be reassigned. const is block-scoped and cannot be reassigned, although object contents can still mutate. Default to const for everything, switch to let only when you actually need to reassign, and avoid var in any code written after 2017.
Which JavaScript version should I target in 2026?
Target ES2020 (ES11) as the safe baseline because every modern browser and Node.js 14+ supports it fully. ES2022 adds useful features like top-level await, private class fields with the # prefix, and the .at() array method. If you are writing for older browsers (IE11 or older Android WebViews), transpile down with Babel or use a build tool like Vite, esbuild, or webpack.
What is the best free editor for JavaScript?
Visual Studio Code is the industry standard, free, with built-in IntelliSense, debugger, terminal, Git, and a huge extension marketplace (ESLint, Prettier, GitHub Copilot, Tailwind). Install the JavaScript and TypeScript Nightly extension for the latest language features. JetBrains WebStorm is more powerful and free for students with a verified .edu email. For quick scratchpad work, the Chrome DevTools Sources panel includes a workspace and breakpoint debugger.
How do I run JavaScript locally vs in the browser?
In the browser: open DevTools with F12 (or right-click then Inspect), go to the Console tab, type or paste your code, press Enter. For HTML pages, add a script tag pointing to your .js file. Locally with Node.js: download Node from nodejs.org (LTS version), then run node script.js in your terminal from the file folder. Use the same Node setup for backend capstones, API integrations, and scripts that do not need a browser.
What can I build with JavaScript for my BSIT capstone?
Common BSIT capstones in JavaScript: full-stack web apps using React or Vue on the front-end with Node.js and Express on the back-end (MongoDB or MySQL for the database), real-time chat or notification systems using Socket.io, single-page dashboards with Chart.js or D3.js, cross-platform mobile apps with React Native, AI-powered chatbots using OpenAI SDK and LangChain.js, and Chrome extensions for productivity tools. Add Tailwind CSS for the UI and Vercel or Netlify for free deployment.

Leave a Comment