Skip to content

Instantly share code, notes, and snippets.

@jpehman
Last active April 27, 2020 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpehman/71fda39ab18f7d0fff29 to your computer and use it in GitHub Desktop.
Save jpehman/71fda39ab18f7d0fff29 to your computer and use it in GitHub Desktop.
(function () {
var charArray = "ABCDEFGHI~`!@JKLMNOPQRSTUVWXYZ#$%^abcdefghijklm&*()nopqrstuvwxyz-_=+1234567890{[}]|:;',.<>?/".split("");
var crypto = window.crypto || window.msCrypto;
if (!crypto.subtle) {
console.log("crypto not supported");
return;
}
function getSalt (strLength) {
strLength = strLength || 64;
var array = new Uint8Array(strLength), salt = "",
arrLength, i = 0;
crypto.getRandomValues(array);
arrLength = array.length;
while (i < arrLength) {
salt += charArray[((new Date()).getTime() + array[i]) % 92];
i += 1;
}
return salt;
}
window.getSalt = getSalt;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment