简体   繁体   English

Base64 + sha256没有给出预期的结果

[英]Base64 + sha256 not giving expected result

I need to figure out why I get the wrong results, here is the thing: 我需要弄清楚为什么我得到错误的结果,这是东西:

Expected result 预期结果

Mu0FBjARVsNyDiixnKqyLCCqVunTSPQFCMnOwGQsIWliY2Jh Mu0FBjARVsNyDiixnKqyLCCqVunTSPQFCMnOwGQsIWliY2Jh

Current Result 当前结果

MzJlZDA1MDYzMDExNTZjMzcyMGUyOGIxOWNhYWIyMmMyMGFhNTZlOWQzNDhmNDA1MDhjOWNlYzA2NDJjMjE2OQ== MzJlZDA1MDYzMDExNTZjMzcyMGUyOGIxOWNhYWIyMmMyMGFhNTZlOWQzNDhmNDA1MDhjOWNlYzA2NDJjMjE2OQ ==

The code I'm using (php) 我正在使用的代码(php)

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

This site http://www.insidepro.com/hashes.php giveme a preety closer result 这个网站http://www.insidepro.com/hashes.php Giveme一个漂亮的结果

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

you can find (in the site, near the result field) a [1], that means "Hash in Base64" 您可以在网站的结果字段附近找到[1],表示“哈希在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. 默认情况下, hash返回其输出的十六进制编码字符串 ,而您期望它返回原始字节。 Luckily it accepts a third argument; 幸运的是,它接受了第三个论点。 set it to true like this: 像这样将其设置为true

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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