The Google App Script function computeDigest returns a byte array of the signature. How can I get the string representation of the digest?
I have already tried the bin2String() function.
function sign(){
var signature = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, "thisisteststring")
Logger.log(bin2String(signature));
}
function bin2String(array) {
var result = "";
for (var i = 0; i < array.length; i++) {
result += String.fromCharCode(parseInt(array[i], 2));
}
return result;
}
but it puts "" in the Logs
Just in case this is helpful to anyone else, I've put together a more succinct version of Mogsdad's solution:
function md5(str) {
return Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, str).reduce(function(str,chr){
chr = (chr < 0 ? chr + 256 : chr).toString(16);
return str + (chr.length==1?'0':'') + chr;
},'');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With