javascript - double hashing sha256 NOTworking!! + how to convert to hex? -
so i've been trying mirror double hashing using sha256 in google script, , not able replicate second hash. first 1 gets replicated correctly, must off first hash being plugged next digest.
var teststring = "hello"; var firsthash=utilities.computedigest(utilities.digestalgorithm.sha_256, teststring); var secondhash=utilities.computedigest(utilities.digestalgorithm.sha_256, firsthash); app.getelementbyid('balancelabel').settext("result: "+secondhash); i first hash , second hash on online converter. first hash matches below expectation, , second doesn't. have tried many things try modify firsthash variable can't seem make work.
this hashes should be: hello 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round of sha-256) 9595c9df90075148eb06860365df33584b75bff782a510c6cd4883a419833d50 (second round of sha-256)
i have been trying hard byte hash , produce hex encoded string (not base64, google script seem support out of box).
can please help?
edit: appears impossible using utitilies.computedigest because accepts string input. however, checked can implement js sha256 function in google script. how double hash using byte input of first hash?
function sign(message){ message = message || "thisisteststring"; var signature = utilities.computedigest( utilities.digestalgorithm.sha_1, message, utilities.charset.us_ascii); logger.log(signature); var signaturestr = ''; (i = 0; < signature.length; i++) { var byte = signature[i]; if (byte < 0) byte += 256; var bytestr = byte.tostring(16); // ensure have 2 chars in our byte, pad 0 if (bytestr.length == 1) bytestr = '0'+bytestr; signaturestr += bytestr; } logger.log(signaturestr); return signaturestr; } you can function converting string disired format
Comments
Post a Comment