Published on

Convert MD5 string to integer bits in JavaScript

Convert MD5 string to integer bits in JavaScript

As we've seen in earlier posts, you can create an MD5 hash of a string and generate a hash in string type. But, what if you had to create a UUID out of it? Practical real-world use-cases can be - if you have a unique ID that you have in your database which you can map.

This implementation is for JavaScript on the frontend (Javascript, React.js, Vue.js etc.,), we implement the same in the backend using the default crypto module for nodejs.

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src=""></script>
    <script src=""></script>
      function MD5toUUID(md5Hash) {
        return (
        md5Hash.substring(0, 8) +
        '-' +
        md5Hash.substring(8, 12) +
        '-' +
        md5Hash.substring(12, 16) +
        '-' +
        md5Hash.substring(16, 20) +
        '-' +

      let digest = "password";
      let hash = CryptoJS.MD5(digest);
      hash = hash.toString(CryptoJS.enc.Base64);

In the above code, you can see that we are passing the hash string to the MD5toUUID function, which returns the UUID value of the md5 hash.

The output of the above code will be a UUID-


I'm glad that you found this article to create UUID from a MD5 hash string useful. Happy Coding.