I want to run the following NodeJS code in Google app script
const CryptoJS = require("crypto-js");
let timeStamp_nonce = Date.now().toString();
let bodystring = `{"ID":"001"}`
const body = JSON.parse(bodystring)
const secret = "secret"
const msg= {
timeStamp_nonce: timeStamp_nonce,
body: JSON.stringify(body)
};
const payload = new Buffer(JSON.stringify(msg)).toString('base64');
const signature = CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA512(payload, secret));
console.log("Payload:", payload)
console.log("\nSignature:",signature)
I tried to convert:
let timeStamp_nonce = Date.now().toString();
let bodystring = `{"ID":"001"}`
const body = JSON.parse(bodystring)
const secret = "secret"
const msg = {
timeStamp_nonce: timeStamp_nonce,
body: JSON.stringify(body)
};
const payload = Utilities.base64Encode(JSON.stringify(msg));
//
// confused on this part...
//
//const signature = CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA512(payload, secret));
//
//
Logger.log("Payload:", i)
Logger.log("\nSignature:",signature)
Can anyone help with this to run in Google Apps script
const payload = CryptoJS.enc.Utf8.parse(JSON.stringify(msg)).toString(CryptoJS.enc.Base64);.