小编del*_*ach的帖子

Hmac Signing in Google Apps Script, When Secret and Digest are base64 encoded

Given this code in nodejs:

const crypto = require('crypto');
const message = 'message to sign';
const secret = 'mysecret';
const signature = crypto.createHmac('sha256', secret).update(message).digest('hex');
console.log(signature);
Run Code Online (Sandbox Code Playgroud)

The output is 40d4c57eed56968de0f3a22e73ebf8abc6ab4c38bba95fd2c85dd4dc90bf36b9

With the help of the answers here, I have exactly replicated this behavior in Google Apps Script, with this function:

//conversion from byte array taken from: /sf/answers/1955342161/
function makeHmacSignature(macAlg, message, secret) {
  return Utilities.computeHmacSignature(macAlg, message, secret).reduce(function(str,chr){
    chr = (chr < 0 ? chr + 256 : chr).toString(16);
    return str + …
Run Code Online (Sandbox Code Playgroud)

javascript base64 hmac node.js google-apps-script

1
推荐指数
1
解决办法
2273
查看次数

标签 统计

base64 ×1

google-apps-script ×1

hmac ×1

javascript ×1

node.js ×1