I'm running node.js and php on windows and I use the included crypto module in node.js.
Php script:
hash_hmac("sha256", "foo", "bar", true) // the true enables binary output
outputs:
¶y3!è¬╝♂ï►ó│Ñ├Fä╚┘CA╝±G6▄rp¸t↑Q
Node.js script:
crypto.createHmac("sha256", "bar").update("foo").digest("binary");
outputs:
¶y3!?ª¼♂?►¢³¥ÃF?ÈÙCA¼ñG6Ürp÷t↑Q
I also wonder why some digits are the same but some others not.
I also tried getting the hex instead of the binary result, both of them output the same.
hash_hmac("sha256", "foo", "bar", false); // false outputs hex data
crypto.createHmac("sha256", "bar").update("foo").digest("hex"); // notice "hex"
This was not a solution because I failed to convert the hex data to binary:
var hmac = crypto.createHmac("sha256", "bar").update("foo").digest("hex");
var binary = new Buffer(hmac, "hex");
The variable binary outputs:
¶y3!???♂?►????F???CA??G6?rp?t↑Q