get back a string representation from computeDigest(algorithm, value) byte[]

后端 未结 6 1946
Happy的楠姐
Happy的楠姐 2020-12-01 14:42

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 b

6条回答
  •  自闭症患者
    2020-12-01 15:41

    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;
      },'');
    }
    

提交回复
热议问题