how to convert hexadecimal hash generated by 'createhash' into string in typescript

To convert a hexadecimal hash generated by createHash into a string in TypeScript, you can use the following code:

index.ts
import { createHash } from 'crypto';

// Create the hash
const hash = createHash('sha256');
hash.update('your_data_here');
const hexHash = hash.digest('hex');

// Convert hexadecimal hash to string
const byteCharacters = hexHash.match(/.{1,2}/g);
const stringHash = byteCharacters.map(byte => String.fromCharCode(parseInt(byte, 16))).join('');

console.log(stringHash);
370 chars
13 lines

Make sure to replace 'your_data_here' with the actual data you used to generate the hash.

related categories

gistlibby LogSnag