hashSHA256
Description
Used for hashing any string using the SHA-256 algorithm. You can also pass a secrect to it for salting the outcome.
If you don't want to use a secret, but wishes to use the tuple parameter, then you need to pass an empty string in the tuple (second) argument.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<string || Array> | |
Related Functions | Function Signature | |
function hashSHA256(supposedString[, secret, tuple]): Promise<string || Array> |
Examples
1
2
3
import { hashSHA256 } from "puddy-m/lib/helpers";
hashSHA256("mark").then((hashedString) => console.log(hashedString)); // prints '835fda2899e58b38a56ec893544c452396f44208fc93494d0089492e97f2486c'
1
2
3
4
5
import { hashSHA256 } from "puddy-m/lib/helpers";
hashSHA256("mark", "thisIsASecret").then((hashedString) =>
console.log(hashedString)
); // prints '5b5efd85fb9b3e396d2664b4755a81a027b30964c87bd30105d1911dfb015ac4'
1
2
3
import { hashSHA256 } from "puddy-m/lib/helpers";hashSHA256("mark", "thisIsASecret", [])
.then((tuple) => hashSHA256("foo", "anotherSecret", tuple))
.then(([hash1, hash2]) => console.log(hash1 + " - " + hash2)); // 5b5efd85fb9b3e396d2664b4755a81a027b30964c87bd30105d1911dfb015ac4 - 8f6efcb1eef9cafadf9210ff4a3109be22804f60bf1ed3d36f1d80ea636481c0
1
2
3
4
5
import { hashSHA256 } from "puddy-m/lib/helpers";
// If you want to use the tuple approach, but no secret, then an empty string should be passed in the secret parameter.
hashSHA256("mark", "", [])
.then((tuple) => hashSHA256("foo", "", tuple))
.then(([hash1, hash2]) => console.log(hash1 + " - " + hash2)); // 835fda2899e58b38a56ec893544c452396f44208fc93494d0089492e97f2486c - 0c0d98f7e3d9d45e72e8877bc1b104327efb9c07b18f2ffeced76d81307f1fff