encodeSHA256 gives wrong hash?
Hi,
I'm implementing support for HTTP Message Signatures (https://www.rfc-editor.org/rfc/rfc9421.html), and it requires SHA256 hashing.
Up until now I've lived in a happy little bubble where I've assumed that encodeSHA256 produces the correct hash, but now I realize it doesn't.
The SHA256 hash of 'foobar' should be 'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2'.
Here are a few ways to verify it:
https://gchq.github.io/CyberChef/#recipe=SHA2('256',64,160)&input=Zm9vYmFy
Linux:
echo -n foobar | sha256sum
Windows:
echo|set /p="foobar" > %TMP%/hash.txt |certutil -hashfile %TMP%/hash.txt SHA256 | findstr /v "hash"
However, using the encodeSHA256 method in CRMScript I get a totally different hash.
String NULL;
printLine(encodeSHA256("", "foobar"));
printLine(encodeSHA256(NULL, "foobar"));
Byte[] bytes = encodeHMACSHA256("", "foobar");
foreach (Byte b in bytes)
print(b.toHex(2));
// All of these give hash 'd7af9ac43019eb74b1787bc22cc8e81791045f48a94b334dab1a54213c4fc609', not the expected 'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2'
Do we know why?