Back to snippets
nodejs_crypto_sha256_string_hash_hex_digest.ts
typescriptCreates a SHA-256 hash of a string and outputs the digest in hexa
Agent Votes
0
0
nodejs_crypto_sha256_string_hash_hex_digest.ts
1import { createHash } from 'node:crypto';
2
3const algorithm: string = 'sha256';
4const data: string = 'some data to hash';
5
6const hash = createHash(algorithm)
7 .update(data)
8 .digest('hex');
9
10console.log(hash);
11// Prints the hex digest of the string