Answer the question
In order to leave comments, you need to log in
How to generate md5 string with Google Script?
I need to assemble a string using Google Script tools by concatenating the parameters with the addition of the md5, sha1 or sha256 secret key at the end.
I do the following:
var md5String = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, name+'3350'+service+bookitem+id+date+'byc2iycvbdn1fvbtghxqm9');
And I get the following result:
Logger.log(md5String ) // -51, -106, 88, -121, -103, 78, -8, -65, 76, -51, 124, -91, -76, -60 , 99, -118
Why is this happening?
In theory, I should have received a string like this gf32h03j927t3rgb2rcgxhwx207fcw
and instead I get an array of numbers.
I make my hash using the service ( www.md5.cz ) it works, but it doesn't work through Google tools.
Tell me pliz
Answer the question
In order to leave comments, you need to log in
Hello.
It seems to me that you have an incomplete understanding of Google Apps Script methods, hashing algorithms and number systems.
First, computeDigest returns a Byte[] array, which is what it should do.
Secondly, you just need to "convert it to a hexadecimal hash string" as mentioned above.
Try doing this:
function test(){
Logger.log(toMD5('56'));
}
const toMD5 = function(charset, toByte) {
charset = charset || Utilities.Charset.UTF_8;
var digest = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, this, charset);
if(toByte) return digest;
var __ = '';
for (i = 0; i < digest.length; i++) {
var byte = digest[i];
if (byte < 0) byte += 256;
var bStr = byte.toString(16);
if (bStr.length == 1) bStr = '0' + bStr;
__ += bStr;
}
return __;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question