generate hmac signature in service now

ChethanB4037292
Tera Contributor

I couldn't able to generate hmac signature which is much required in every platform for validations and no such capability is figured in service now,I don't know any one faced this issue or not.

I referred this discussion as well but its not working as per the code provided : 

https://www.servicenow.com/community/developer-forum/alternative-solution-for-generating-hmac-sha256...

 

 

Highly appreciated for quick support here!!!

5 REPLIES 5

Maik Skoddow
Tera Patron
Tera Patron

Hi @ChethanB4037292 

 

the code is working as expected. The only pitfall: You need to create a custom application first, and within that custom application create the Script Include you can receive from https://gist.githubusercontent.com/vetsin/117cfe99ab0f87c1ac2d5c6387d1f7b4/raw/f4dc199b945ca56292ec0.... Then use my below code as an example. It works!

 

MaikSkoddow_0-1744975551655.png

Maik

 

Hi @Maik Skoddow ,

Thanks for your reply,

I tried and I can able to generate it, but the way we generate in python or go langauages it gives different value comparing to this flow what you had shared.

ex : I'm using standard lib to generate hmac in python lang 

 

import hmac
import base64
import hashlib


secret="abcd"
payload="helloworld"
hmac_object = hmac.new(secret.encode(), payload.encode(), digestmod=hashlib.sha256)
base64_hmac = base64.b64encode(hmac_object.digest()).decode("utf-8")
generated_signature = f"sha256={hmac_object.hexdigest()}"
print(f"Generated HMAC: {generated_signature}")

 

 the service now o/p with that script is different : 

 

o/p : Generate HMAC from service now : 3oGXgIDz8yRpGfWMAnI0Tt5A0IfyRNlCd7dP3t6Ue0U=
Generated HMAC from python : de81978080f3f3246919f58c0272344ede40d087f244d94277b74fdede947b45

 

 

Hi @Maik Skoddow ,

Thanks for your reply, I tried and I can able to generate it, but the way we generate in python or go langauages it gives different value comparing to this flow what you had shared.

ex : I'm using standard lib to generate hmac in python lang

import hmac import base64

import hashlib

secret="abcd"

payload="helloworld"

hmac_object = hmac.new(secret.encode(), payload.encode(), digestmod=hashlib.sha256)

base64_hmac = base64.b64encode(hmac_object.digest()).decode("utf-8")

generated_signature = f"sha256={hmac_object.hexdigest()}"

print(f"Generated HMAC: {generated_signature}")

the service now o/p with that script is different :

o/p : Generate HMAC from service now : 3oGXgIDz8yRpGfWMAnI0Tt5A0IfyRNlCd7dP3t6Ue0U=

Generated HMAC from python : de81978080f3f3246919f58c0272344ede40d087f244d94277b74fdede947b45

Hey @ChethanB4037292 !

Your first string is base64 and your second one is hex 😉 Try converting the first string to hex or the second string to base64 and see what you get!

Mark my note as helpful and enjoy a bug free (or at least bug-lite) day🐛