Trying to get the digest using crypto.hmac(sha256,API_Key) process and then to update a text to the hmac

Manoj Kumar16
Giga Guru

I am trying to get a digest in Hex format in ServiceNow as the requirement is to get the authentication code using the below Node.JS script-

//computing signature

const crypto = require('crypto');

const hmac = crypto.createHmac('sha256', API_KEY);

hmac.update("Error String");    // hash the form text to provide authentication

const digest = hmac.digest('hex');

console.log(digest);

I have used the below method to get the digest-

var mac = new GlideCertificateEncryption;
var key="API_KEY";
key = GlideStringUtil.base64Encode(key);
var text=mac.generateMac(key, "HmacSHA256", "Error String");

 
var digest = new GlideDigest();
gs.print(digest.getSHA256Hex(text));

It's giving me an incorrect output. Could anybody suggest me the right way to obtain the digest ?

Thanks in advance,

Manoj Kumar.

4 REPLIES 4

Khanna Ji
Tera Guru

Have you managed to get a solution for this? Looking for same.

Hi @Khanna Ji

Were you able to find the solution for this?

 

Thanks

tantony
Mega Guru

Did you find a solution for this? I have same requirements for an authentication HTTP header for a REST call

Hi @tantony

Were you able to find the solution for this?

 

Thanks