Node.js - MD5, SHA-1, SHA-256, SHA-384, SHA-512 Example

What does Hashing mean?

A secure password hash is an encrypted sequence of characters obtained after applying certain algorithms and manipulations on utilizer-provided passwords, which are generally very impotent and facile to conjecture.
Please remember that once this password hash is engendered and stored in the database, you can not convert it back to the pristine password.


Using MD5 algorithm

The MD5 message-digest algorithm is a widely used hash function engendering a 128-bit hash value. Albeit MD5 was initially designed to be utilized as a cryptographic hash function, it has been found to suffer from extensive susceptibilities. It can still be utilized as a checksum to verify data integrity, but only against unintentional corruption. It remains felicitous for other non-cryptographic purposes, for example for determining the partition for a particular key in a partitioned database.

Node.js MD5 Example:

var crypto = require('crypto');

var data = "Your Password";
const hash = crypto.createHash('md5').
update(data).digest("hex");
console.log('Hash successfully generated: ', hash);

Output:



Using the SHA-1 algorithm

In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function that takes an input and engenders a 160-bit (20-byte) hash value kenned as a message digest – typically rendered as a hexadecimal number, 40 digits long. It was designed by the United States National Security Agency and is a U.S. Federal Information Processing Standard.

Node.js SHA-1 Example:

var crypto = require('crypto');

var data = "Your Password";
const hash = crypto.createHash('sha1').
update(data).digest("hex");
console.log('Hash successfully generated: ', hash);

Output:




Using the SHA-256 algorithm

The SHA (Secure Hash Algorithm) is one of a number of cryptographic hash functions. A cryptographic hash is like a signature for a text or a data file. SHA-256 algorithm engenders a virtually unique, fine-tuned size 256-bit (32-byte) hash. 

Node.js SHA-256 Example:

var crypto = require('crypto');

var data = "Your Password";
const hash = crypto.createHash('sha256').
update(data).digest("hex");
console.log('Hash successfully generated: ', hash);

Output:




Using the SHA-384 algorithm

Sha-384 is a function of the cryptographic algorithm Sha-2, the evolution of Sha-1. It's the same encryption as Sha-512, except that the output is truncated at 384 bits. There are withal differences in the initialization process. This function is a component of the U.S Federal Information Processing Standard.

Node.js SHA-384 Example:

var crypto = require('crypto');

var data = "Your Password";
const hash = crypto.createHash('sha384').
update(data).digest("hex");
console.log('Hash successfully generated: ', hash);

Output:




Using the SHA-512 algorithm

SHA-512 is very close to Sha-256 except that it used 1024 bits "blocks", and accept as input a 2^128 bits maximum length string. SHA-512 also has other algorithmic modifications in comparison with Sha-256.

SHA-512 Example:

var crypto = require('crypto');

var data = "Your Password";
const hash = crypto.createHash('sha512').
update(data).digest("hex");
console.log('Hash successfully generated: ', hash);

Output:

Popular posts from this blog

Spring boot video streaming example-HTML5

Learn Java 8 streams with an example - print odd/even numbers from Array and List

Spring Boot + Mockito simple application with 100% code coverage

Spring Boot + OpenCSV Export Data to CSV Example

Custom Exception Handling in Quarkus REST API

DataTable-Pagination example with Spring boot, jQuery and ajax

Registration and Login with Spring Boot + Spring Security + Thymeleaf

Node JS mini projects with source code - free download

Spring boot web project free download:User Registration System

Java - Blowfish Encryption and decryption Example