SHA512 Hashing algorithm in node.js


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. Code snippet is given below :


//Name of the file : sha512-hash.js
//Loading the crypto module in node.js
var crypto = require('crypto');
//creating hash object 
var hash = crypto.createHash('sha512');
//passing the data to be hashed
data = hash.update('nodejsera', 'utf-8');
//Creating the hash in the required format
gen_hash= data.digest('hex');
//Printing the output on the console
console.log("hash : " + gen_hash);



  • Now run the snippet using the following command :
    >node sha512-hash.js
    hash : 45be99fad36ea7962165979444acbf558bd5c5837ae7389e3aebb48d41c6cf1aa44908d4dcd12db963f005f8d30e2e2cdda6b7499