Last active
April 18, 2018 00:44
-
-
Save tech4him1/09244db980a7e9dd4ddde2b70fe95245 to your computer and use it in GitHub Desktop.
Generate random SHA256 look-alike.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hashlen = 256; | |
const hashbase = 16; | |
const randomNums = new Uint32Array(hashlen / 32); | |
window.crypto.getRandomValues(randomNums); | |
const padNum = (num, base) => { | |
const padLen = (32 / Math.sqrt(base)); | |
const str = num.toString(base); | |
return (('0' * padLen) + str).slice(-padLen); | |
} | |
const randomSHA256 = randomNums.reduce((agg, val) => (agg + padNum(val, hashbase)), ''); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment