To create a SHA512 hash from a string in TypeScript, you can use the createHash
function from the built-in crypto
module of Node.js. Here's an example code:
index.ts282 chars12 lines
In this code, we define a function sha512
that takes a string input, creates a SHA512 hash object using crypto.createHash('sha512')
, updates the hash with the input using hash.update(input)
, and finally returns the hexadecimal representation of the hash using hash.digest('hex')
.
To use this function, simply call it with your input string (in this case, 'your string to hash'
) and store the output hash value in a variable (in this case, output
). You can then print or use the hash value as needed.
gistlibby LogSnag