SHA-256 (Secure Hash Algorithm 256-bit)
- SHA-256 is a robust cryptographic hash function. It computes a fixed-size, 64-character hash value from data, offering strong data integrity and security.
- Make a
calculateSHA256
function that employs Node.js’s crypto library to compute a SHA-256 checksum. - It initializes a SHA-256 hash object, incorporates the provided data, and then produces the checksum.
- SHA-256 is a robust cryptographic hash function widely used for data integrity verification.
- Now the resulting checksum, presented in hexadecimal form, acts as a secure representation of the input data.
Example: In this example we will see the implementation of checksum algorithm by using SHA-256.
Javascript
const crypto = require( "crypto" ); // Calculate a SHA-256 checksum for // the given data using Node.js's crypto library function calculateSHA256(data) { // Create a SHA-256 hash object const hash = crypto.createHash( "sha256" ); // Update the hash object with the data hash.update(data); // Generate the SHA-256 checksum // in hexadecimal format return hash.digest( "hex" ); } const data = "HGeeks For Geeks" ; const sha256Value = calculateSHA256(data); console.log( "SHA-256 Checksum: " + sha256Value); |
SHA-256 Checksum: c41f05cb05c78ab992132d4c4335774303e7a8e85600362bd6b5cdadf14229a5
Checksum algorithms in JavaScript
Checksum algorithms are fundamental techniques used in data communication and storage to ensure the integrity of data. The primary purpose of a checksum algorithm is to generate a fixed-size value (the checksum) based on the content of a dataset. They are essential for detecting errors, unauthorized changes, or corruption in data during transmission, saving files, or other data-handling processes.
These are the following techniques for this:
Table of Content
- Simple Checksum
- CRC (Cyclic Redundancy Check)
- MD5 (Message Digest Algorithm 5)
- SHA-256 (Secure Hash Algorithm 256-bit)