Convert String in Hash SHA-256 format with NUL(e.g. "/000")

285 Views Asked by At

Using JMETER, I would like to convert below String in SHA - 256 Hash key notation

624111NUL2021-10-06T11:35:39-04:00NULs3cr3tNUL,

The correct supposed to be

7c3f952cdd1d6bf56a2762c5bb94add00883654794d27344f1dd55e5901f381c

while using below hash function

${__digest(SHA-256,624111NUL2021-10-06T11:35:39-04:00NULs3cr3tNUL,,,)}

Unfortunately not getting the correct result from the above function, I came to know, NUL characters between the fields and at the end (3 total NUL characters). These are hex 00 characters. They show as NUL in Notepad++ but they are really hex 00. e.g. Id+ "\000" + timestamp + "\000" + salt + "\000"

Any idea to manage the same in JMeter to get correct SHA 256 Key

1

There are 1 best solutions below

2
Dmitri T On

Just go for __groovy() function which allows executing arbitrary Groovy code where you can have Unicode escape sequences:

${__groovy(org.apache.commons.codec.digest.DigestUtils.sha256Hex('624111\0002021-10-06T11:35:39-04:00\000s3cr3t\000'),)}

enter image description here