Calculate a SHA256 hash
Problem
You want to generate a SHA 256 hash of a value for use in your application.
Solution
Use the built-in $crypto.sha256()
function to receive a string of the SHA 256 hash.
For example in a TypeScript Client function:
Code example
const myHash = $crypto.sha256("dynaboard")
return myHash // => 0d52901032dbf3b9a726d1784600541141a513604f0bb083268f2929ca6b5100
Discussion
- The
$crypto
library is available on both TypeScript Client and TypeScript Server resource functions. - To take the SHA256 hash of a non-string value, you must first convert it to a string, for example using
String(val)
orJSON.stringify(val)
.