SHA1 Hashing algorithm in node.js


Overview

Secure Hash Algorithm 1 is a cryptographic hash function which generates a hash value which is typically rendered as a hexadecimal number of exactly 40 digits long. It produces a 160-bit hash value which is known as message digest.

Code


													
//Loading the crypto module in node.js
var crypto = require('crypto');
//creating hash object 
var hash = crypto.createHash('sha1');
//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);
						
					

													
												

Run

  • Now run the snippet using the following command :
    													
    >node sha1-hash.js
    hash : 387d3143b0baa6beb292eda4f81b2d33e55c6744