简体   繁体   中英

Base64 + sha256 not giving expected result

I need to figure out why I get the wrong results, here is the thing:

Expected result

Mu0FBjARVsNyDiixnKqyLCCqVunTSPQFCMnOwGQsIWliY2Jh

Current Result

MzJlZDA1MDYzMDExNTZjMzcyMGUyOGIxOWNhYWIyMmMyMGFhNTZlOWQzNDhmNDA1MDhjOWNlYzA2NDJjMjE2OQ==

The code I'm using (php)

echo base64_encode(hash("sha256", $pass.$salt'));

This site http://www.insidepro.com/hashes.php giveme a preety closer result

sha256($pass.$salt) => Mu0FBjARVsNyDiixnKqyLCCqVunTSPQFCMnOwGQsIWk=

you can find (in the site, near the result field) a [1], that means "Hash in Base64"

the thing is... I can't even get the sites result


EDIT (Thanks Jon)

now the code goes like this

echo base64_encode(hash("sha256", $pass.$salt', true));

I'm getting the same result as in the site


the problem now is the difference between the two results

actual result   : Mu0FBjARVsNyDiixnKqyLCCqVunTSPQFCMnOwGQsIWk=
expected result : Mu0FBjARVsNyDiixnKqyLCCqVunTSPQFCMnOwGQsIWliY2Jh

hash returns a hex-encoded string of its output by default, while you are expecting it to return raw bytes. Luckily it accepts a third argument; set it to true like this:

echo base64_encode(hash("sha256", $pass.$salt', true));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM