I don't understand much about string hashing but I would like to compare a string hashed in SHA3-256 using the messageDigest() function with a hashed string in Javascript.
On the Javascript side, I found this:
https://coursesweb.net/javascript/jssha-hash-hmac
My problem is that the same string hashed by LC and by Javascript gives a different result.
My LC code:
Code: Select all
put hashSha3Test(fld "OriginalString", true)
put hashSha3Test(fld "OriginalString", false)
function hashSha3Test str, returnHex // SHA3-256
// if returnHex set to true, returns hex. if false, returns base64
put messageDigest(textEncode(str, "UTF-8"), "SHA3-256") into hashedStr
if (returnHex) then
get binaryDecode("H*", hashedStr, tHex)
return tHex
else return base64Encode(hashedStr)
end hashSha3Test
Code: Select all
var originalString = 'Test';
var hash;
var sha_ob = new jsSHA('SHA3-256', 'TEXT');
sha_ob.update(originalString);
hash = sha_ob.getHash('HEX');
console.log('HEX=' + hash);
hash = sha_ob.getHash('B64');
console.log('B64=' + hash);
Thank you.