
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2020 12:28 PM
I am trying to do the ServiceNow JS equivalent of the following Python code:
hmac = hmac.new("key".encode(), "message".encode(), digestmod=hashlib.sha256).hexdigest()
I thought it would be this, but it's not resulting in the same hash as Python:
var encryption = new GlideCertificateEncryption();
var digest = new GlideDigest();
var util = new GlideStringUtil();
var key = utf8Encode("key"); // utf8Encode() is my own function which is working fine
var message = utf8Encode("message");
var signatureMacBase64 = encryption.generateMac(util.base64Encode(key), "HmacSHA256", message);
var signatureDigest = digest.getSHA256Hex(signatureMacBase64);
The output I'm expecting (for "key" and "message" as inputs) in hex is:
6e9ef29b75fffc5b7abae527d58fdadb2fe42e7219011976917343065f58ed4a
Any help appreciated!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2020 02:14 PM
I solved it:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2020 02:14 PM
I solved it: