javascript - Computing SHA1 hash of a file in Google Drive -
i need compute sha-256 hash of file uploaded via ajax google drive in appscript deployed web-app. in server code, computing this:
function gethash(file) { var hashbytes = utilities.computedigest(utilities.digestalgorithm.sha_256, file.getblob().getdataasstring()); // convert raw bytes base16-encoded string var hash = ""; for(var i=0; i<hashbytes.length; i++) { var byte = hashbytes[i]; if(byte < 0) { byte += 256; } var bytestring = byte.tostring(16); // if byte not represented 2 chars must 0-padded if(bytestring.length == 1) { bytestring = '0' + bytestring; } hash += bytestring; return hash; }
however, computed hash different 1 same file e.g. executing
shasum -a 256 myfile
in bash shell. there wrong in gethash() function?
i'd need function work on file type.
Comments
Post a Comment