JavaScript MD5
Demo
JavaScript MD5 Demo
Description
JavaScript MD5 implementation. Compatible with server-side environments like node.js, module loaders like RequireJS and all web browsers.
Usage
Client-side
Include the (minified) JavaScript MD5 script in your HTML markup:
<script src="js/md5.min.js"></script>
In your application code, calculate the (hex-encoded) MD5 hash of a string by calling the md5 method with the string as argument:
var hash = md5("value");
Server-side
The following is an example how to use the JavaScript MD5 module on the server-side with node.js.
Create a new directory and add the md5.js file. Or alternatively, install the blueimp-md5 package with npm:
npm install blueimp-md5
Add a file server.js with the following content:
require("http").createServer(function (req, res) {
var md5 = require("./md5").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/");
Run the application with the following command:
node server.js
Requirements
The JavaScript MD5 script has zero dependencies.
API
Calculate the (hex-encoded) MD5 hash of a given string value:
var hash = md5("value");
Calculate the (hex-encoded) HMAC-MD5 hash of a given string value and key:
var hash = md5("value", "key");
Calculate the raw MD5 hash of a given string value:
var hash = md5("value", null, true);
Calculate the raw HMAC-MD5 hash of a given string value and key:
var hash = md5("value", "key", true);
License
The JavaScript MD5 script is released under the MIT license.