Faster SHA256 Digest Calculation

735 views
Skip to first unread message

Tejaswa Rastogi

unread,
Mar 28, 2022, 12:15:25 PM3/28/22
to Google Apps Script Community
Hi Everyone,

I'm looking forward to have a faster SHA256 hash calculation.

My current implementation looks like this where url points to the uploaded file on telegram server

var response = UrlFetchApp.fetch(url);
var fileText = response.getContent();
var bytes = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256, fileText);
var hexstr = bytes.map(byte => ('0' + (byte & 0xFF).toString(16)).slice(-2)).join('');
return hexstr;

which takes 4-5 seconds for a 2MB file. How can I improve/optimize my code to do it faster?

Reply all
Reply to author
Forward
0 new messages