I am trying to conduct a hashing operation in BITS mode using Javascript.
The examples below I am trying to hash the following binary string: 0010010011100100
In BITS mode, ASCII '0' is interpreted as 0-bit, ASCII '1' interpreted as 1-bit, and all other characters are ignored. Read more here.
I can obtain the expected output in the command line with echo 0010010011100100 | shasum -a 256 -0, which outputs the expected result (86e89f2cdc1c84f2722cb39341c1888113d61a66f46df75803cfce9d5c9a8637)
However, I am unable to figure out how to get the same output in JS (preferably plain JS with no libraries). I keep getting a "non-BITS mode" result.
Here is what I have so far. This outputs a normal hash (without BITS mode).
const crypto = require('crypto');
function sha256(string) {
return crypto.createHash('sha256').update(string).digest('hex');
}
Any ideas would be great! Thanks!