Generating HMAC using md5 hashing algorithm


Overview

MD5 stands for message digest 5 is a widely used hash function which produces 128-bit hashes. HMAC involves hashing with the help of a secret key as shown in the snippet below :

Code


													
//Name of the file : md5-hmac.js
//Loading the crypto module in node.js
var crypto = require('crypto');
//creating hmac object 
var hmac = crypto.createHmac('md5', 'yoursecretkeyhere');
//passing the data to be hashed
data = hmac.update('nodejsera');
//Creating the hmac in the required format
gen_hmac= data.digest('hex');
//Printing the output on the console
console.log("hmac : " + gen_hmac);
													
												

Run

  • Now run the snippet using the following command :
    													
    >node md5-hmac.js
    hmac : d79672cea8d7d6a61d40bd27373b0a30