hashSHA512
Description
Used for hashing any string using the SHA-512 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 hashSHA512(supposedString[, secret, tuple]): Promise<string || Array> |
Examples
1
2
3
4
import { hashSHA512 } from "puddy-m/lib/helpers";
hashSHA512("foo bar")
.then((hashedStr) => console.log(hashedStr)); // e7b4fe8e51d37a4be40eee7aff6aad7881136d7d8ce5f4019809adac9641978d9295d657227fee4a3cb26269c7140977c94dc6455d3050430fb61f5ca5bb2756
1
2
3
4
5
import { hashSHA512 } from "puddy-m/lib/helpers";
// hashSHA512 with secrect
hashSHA512("foo bar", "this is a secret")
.then((hashedStr) => console.log(hashedStr)); // f92b1a3c01648dc76241dcaf700f374debdf2048861d5dcb9b64d0196bf097033a8e96b9da1973834d70e69279ffd7019485aed2a22ef42053cacc88c229ccad
1
2
3
4
5
6
7
8
import { hashSHA512 } from "puddy-m/lib/helpers";
import { validateString } from "puddy-m/lib/validators";
validateString("fizz buzz")
.then((fizzBuzz) => hashSHA512(fizzBuzz, "this is a secret",[]))
.then((tuple) => hashSHA512("anotherString", "this is a secret",tuple))
.then(([hashedFizzBuzz, hashedAnotherString])=>console.log(hashedFizzBuzz + " - " + hashedAnotherString)); // 2201b767c0e4a02574329a67272fa350a80f0f70363fd973ea8b6bd7dd4d8f4f6ffad52c49210b203c9cc9ab033139940315ec4d98be78fa855450b56ea1eccf - 803d2e07a5f0dfebef3700854b625063ed9b0ff286fb04bf75e60533960e4294d1e257f6584c5b6a842bd6e87a1b9a2f1a891970d6104ff662b3dacdec531ba2
1
2
3
4
5
6
7
import { hashSHA512 } from "puddy-m/lib/helpers";
// If you intend to use no secret, then an empty string needs to be passed if you intend to use tuple
hashSHA512("fizz buzz", "",[])
.then((tuple) => hashSHA512("anotherString", "",tuple))
.then(([hashedFizzBuzz, hashedAnotherString])=>console.log(hashedFizzBuzz + " - " + hashedAnotherString)); // ed6d28ec09b3c3a5e9d34a8636e5b774fe075831c561ad3aee560b6188dfd140c9ec1550b0468ea9b88b467fe88d8c93044b96b0b4c5d8b1841650a5fd505f30 - fdd69c6605ea62b0807ebb1dcb4ab0e8d0e2a06395f3fa417b8096a20b11e8a1d94b8b9f1fdb6ad39c2f4a0021a35aaf34d30ace814dd7591f29df63667b64cd