Back to snippets
nodejs_crypto_sha256_string_hash_to_hex.ts
typescriptCreates a SHA-256 hash of a string and outputs the result in hexa
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