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)