Generating HMAC using sha512 hashing algorithm


Secure Hash Algorithm 512 comes under SHA2 and it is a cryptographic hash function which is used to generate hash values.It produces a 512-bit hash value which is known as message digest. HMAC involves hashing with the help of a secret key as shown in the snippet below :


//Name of the file : sha512-hmac.js
//Loading the crypto module in node.js
var crypto = require('crypto');
//creating hmac object 
var hmac = crypto.createHmac('sha512', '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);


  • Now run the snippet using the following command :
    >node sha512-hmac.js
    hmac : a81b6b65c3df83ae15fe185dd16dc9c846f9e3cb567292422785954130047ac10e2547f505515ea4a20de7e335e60d6489ae71bbf