I am currently encoding a SHA-256 hash in a browser extension like this:
var hash = "arbitraryString";
const hash2 = await crypto.subtle.digest("SHA-256", (hash));
const hashArray = await Array.from(new Uint8Array(hash2));
const hashHex = await hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
var length = 32;
var hashHexString = hashHex.substring(0,length);
This yields a 32 digit string comprised of only lowercase letters and numbers. Is there a way to change the encoding, or something else, that will yield a string with lowercase, uppercase, numbers and special chars?
When trying anything like:
const hashHex = await hashArray.map(b => b.toString(64).padStart(2, '0')).join('');
I get this error: "RangeError: toString() radix argument must be between 2 and 36"
Does this mean I can't use such a simple encoding function to create the desired lower/upper/number/special chars string in javascript (within a browser extension) without the addition of other libraries?