Skip to main content

Command Palette

Search for a command to run...

Generating HMAC using crypto sha512 hashing

Published
1 min read

Secure Hash Algorithm 512 (SHA-512) is a cryptographic hashing algorithm which is used to convert text of any length into a fixed-size string (hash values). It produces a 512-bit (64bytes) hash value which is known as message digest used commonly for hashing passwords, email addresses and digital record verification. Interestingly, it is also used in blockchain as can be seen in the Bitshares (BTS) network. Read more here...

HMAC involves hashing with the help of a secret key as shown below;

Code


//Import the crypto module in node.js
const crypto = require('crypto');

//create hmac object 
const hmac = crypto.createHmac('sha512', {{your_secret_key}});

//pass the data to be hashed
const data = hmac.update({{ data }});

//Create the hmac in the required format
const hmacsignature = data.digest('hex');

//Log the output on the console
console.log(`hmac : ${hmacsignature}`);

Run

Command —>

- node {{filename}}.js

Expected result —>

- hmac : a81b6b65c3df83ae15fe185dd16dc9c846f9e3cb567292422785954130047ac10e2547f505515ea4a20de7e335e60d6489ae71bbfcf130114672e95603dc4571

More from this blog

E

Ebugo writes

13 posts