hmacSHA256(Hex decimal hash) signature generation with CryptoJS in servicenow

dayalsingh
Kilo Explorer

Hello Guys,

-1

I am using cryptoJS Lib for generating Hex HMACSHA256 signature for AWS4 request.Its working fine in custom application scope but in sn_capi scope throws me error undefined properties.

gist.github.com/igable/4bdcd90f78a8b2b07581 ..I have used this cryptojs file in the above link in my servicenow "script include" which is in sn_capi/cloud API scope when i hit this code with command var CryptoJS = new sn_capi.Crypto().CryptoJS; var kRegion = CryptoJS.HmacSHA256('regionName', 'kDate'); gs.info(kRegion); to get the hash i gets an error "undefined properties" at lines 1,8,50,149,186 but this works fine in custom application scope.I am able  to generate hash value in custom application scope but fails in sn_capi scope.Can anyone guide me on this.

Hey @dave.slusher can you guide me on this.

@Chuck Tomasi @Pradeep Sharma @Brad Tilton 
@Mark Stanger 
@Anurag Tripathi 
@josh.nerius 
@Göran Lundqvist 

 

11 REPLIES 11

Omkar Mone
Mega Sage

I know this is an old thread but might help someone.

 

I have been through the same situation in one of my previous engagements and the below script actually helped me generate the token with HmacSha256

 

var secretkey = "secret_test";
var ge = new GlideEncrypter();
secretkey = ge.decrypt(secretkey);
var MAC_ALG_3 = "HmacSHA256";
var mac = new GlideCertificateEncryption;
secretkey = GlideStringUtil.base64Encode(secretkey);

var base64string = mac.generateMac(secretkey, MAC_ALG_3, "testing the string encryption with HMACSHA256");
gs.log("The token should be - " + base64string);

 

Hope this helps.

 

Regards,

Omkar

Hi Omkar,

 

Thanks you very much for this script. I've been looking for this for over a month and I was able to produce the right base64string with your code. Although I'm having another issue with the API, the problem with deriving the signature is gone. Thanks!