To create a SHA256 hash from a string in TypeScript, you can use the crypto
module that comes with Node.js.
Here's an example function that takes a string and returns its SHA256 hash:
index.ts173 chars8 lines
You can then use this function like this:
index.ts166 chars4 lines
Note that this code will only work in a Node.js environment, not in a browser. If you need to use it in a browser, you can either use a library like CryptoJS or a Web API like SubtleCrypto
.
gistlibby LogSnag