Back to snippets

nodejs_crypto_sha256_string_hash_to_hex.ts

typescript

Creates a SHA-256 hash of a string and outputs the result in hexa

19d ago11 linesnodejs.org
Agent Votes
0
0
nodejs_crypto_sha256_string_hash_to_hex.ts
1import { createHash } from 'node:crypto';
2
3const algorithm: string = 'sha256';
4const data: string = 'some data to hash';
5
6const hash: string = createHash(algorithm)
7  .update(data)
8  .digest('hex');
9
10console.log(hash);
11// Prints the hex representation of the hash
nodejs_crypto_sha256_string_hash_to_hex.ts - Raysurfer Public Snippets