How To Generate hash value equivalent to node.js in php


I have been facing a problem in my Project. I want to generate a hash which is equivalent to node.js hash value.
Here is my Node.js code


Which generates e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

And my PHP code is

$secret_key = hash('sha256', '', true);
$contentHash = hash_hmac('sha256', '', $secret_key);

Which generates bfe4527091e7291c5b9a9359c579a97302ba3a7d969994f80a562db7bad4315c

I want to generate same hash value though the platform is different.


You don’t want HMAC, you just want straight SHA256 in hex format:

$string = '';
$hash = hash('sha256', $string);
echo $hash;



Answered By – Alex Howansky

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published