Using CryptoJS i got as a result a byte[8] when I need a 32 one, this code exactly:
CryptoJS.SHA256(word);
How to get the 32?
Using CryptoJS i got as a result a byte[8] when I need a 32 one, this code exactly:
CryptoJS.SHA256(word);
How to get the 32?
This feels a bit convoluted, but I don't have a lot of experience with CryptoJS so perhaps there's a solution that requires less steps:
const CryptoJS = require('crypto-js');
let hash = CryptoJS.SHA256('hello world');
let buffer = Buffer.from(hash.toString(CryptoJS.enc.Hex), 'hex');
let array = new Uint8Array(buffer);
If you need a proper JS array (one for which Array.isArray
returns true
), you can use this:
let array = Array.from( new Uint8Array(buffer) );
The solution was in my case:
let utf16le = CryptoJS.enc.Utf16LE.parse(word);
let utf16Sha256 = CryptoJS.SHA256(utf16le);
return utf16Sha256.toString(CryptoJS.enc.Hex);
thanks to someone's else question