Do you know that MD5 libraries are often required by JavaScript developers, It can be a client or server side that can help confirm file data, and one of the most popular libraries is the  blueimp-md5 library? 



What is MD5?

  • It's the regulated as a 1-way function 
  • MD5 implementations produce a 128-bit hash value from a data string
  • Any data is capable to input in fixed-size output string
  • It includes Graphic showing inputs, hash functions, and hash sums


Remember that:

  • Same data input maps to the same output. 
  • Identical outputs from different inputs are rare but can happen.
  • md5sum is the command line tool for MD5 hashing, for Linux systems 
  • Some of the operating systems have similar commands.


For Client-Side Installation and Usage

What you need to do  first is to download the md5.min.js library then you need to include it in your HTML:


<script src="js/md5.min.js"></script>


What is the next thing to do? Calculate the MD5 hex-encoded hash of a string in your JS application code. How you will do that? you need to call the md5 method as an argument with your string value. 


<em>var</em> hash = md5("value"); // "2063c1608d6e0baf80249c42e2be5804"


You will find more examples of using the library API below:


For Server-Side Installation and Usage with NodeJs


You can use the MD5 library on the server side with NodeJS, then you can install the blueimp-md5 package by this:

npm install blueimp-md5


In the following code you will learn ow the MD5 package can be used to MD5 hash a query URL string


require("http").createServer(function (req, res) {

 

    var md5   = require("blueimp-md5"),

        url   = require("url"),

        query = url.parse(req.url).query;

 

    res.writeHead(200, {"Content-Type": "text/plain"});


    res.end(md5(query));

 

}).listen(8080, "localhost");

 

console.log("Server running at http://localhost:8080/ open this URL in your browser to see its MD5 hash");


After that you now can run this NodeJS application:

node server.js


These are the API Examples, the library has one function that can take up three arguments:


Required: Input string MD5 hashed must be present.

Optional: The HMAC key value is for message authentication by using the cryptographic hash functions such as MD5 with a secret shared key.


You can find here the codes examples of this API:


Calculate the hex-encoded MD5 hash of a given string value:


var hash = md5("value"); // "2063c1608d6e0baf80249c42e2be5804"