php bin2hex,base64_encode;不同的输入相同的输出(循环中)?
我试图创建一个文件名哈希(键)和文件名(值)的数组,但我使用的大多数函数似乎并不像我希望的那样工作...
为什么这些函数在循环中使用时会产生相同的结果当输入字符串变化时输出字符串? md5 和 sha1 没有这个问题,但不可逆,这是需要的。
foreach ($files as $file)
{
debug(array(bin2hex($file), $file));
}
// result
app/views/helpers/monolith.php (line 45)
Array
(
[0] => 2f686f6d652f6d746572736d697474656e2f7075626c69635f68746d6c2f6170702f707269766174652f6d622f323031302f31322e706466
[1] => /home/mtersmitten/public_html/app/private/mb/2010/12.pdf
)
app/views/helpers/monolith.php (line 45)
Array
(
[0] => 2f686f6d652f6d746572736d697474656e2f7075626c69635f68746d6c2f6170702f707269766174652f6d622f323031302f31312e706466
[1] => /home/mtersmitten/public_html/app/private/mb/2010/11.pdf
)
app/views/helpers/monolith.php (line 45)
Array
(
[0] => 2f686f6d652f6d746572736d697474656e2f7075626c69635f68746d6c2f6170702f707269766174652f6d622f323031302f31302e706466
[1] => /home/mtersmitten/public_html/app/private/mb/2010/10.pdf
)
我希望这个例子更清楚......
I trying to create an array of filename hashes (key) and filenames (value), but most functions I use don't seem to work like I want them to...
Why are these functions when used in a loop resulting in the same output string while the input string varies? md5 and sha1 don't have this problem, but aren't reversible and that's needed.
foreach ($files as $file)
{
debug(array(bin2hex($file), $file));
}
// result
app/views/helpers/monolith.php (line 45)
Array
(
[0] => 2f686f6d652f6d746572736d697474656e2f7075626c69635f68746d6c2f6170702f707269766174652f6d622f323031302f31322e706466
[1] => /home/mtersmitten/public_html/app/private/mb/2010/12.pdf
)
app/views/helpers/monolith.php (line 45)
Array
(
[0] => 2f686f6d652f6d746572736d697474656e2f7075626c69635f68746d6c2f6170702f707269766174652f6d622f323031302f31312e706466
[1] => /home/mtersmitten/public_html/app/private/mb/2010/11.pdf
)
app/views/helpers/monolith.php (line 45)
Array
(
[0] => 2f686f6d652f6d746572736d697474656e2f7075626c69635f68746d6c2f6170702f707269766174652f6d622f323031302f31302e706466
[1] => /home/mtersmitten/public_html/app/private/mb/2010/10.pdf
)
I hope this example is more clear...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实上,字符串是不同的。你应该更仔细地检查一下。它们在很大程度上是相同的,因为 bin2hex 和 base64_encode 都对字节序列进行编码,并且不会生成像 sha1 或 sha1 那样的哈希值。 md5。
bin2hex 只是将字符串中的每个字符转换为其十六进制值,至于 base64,请检查 wikipedia 文章 来准确了解为什么大部分结果的字符串是相同的
In fact the strings are different. You should check more carefully. They are the same for the most part, because both bin2hex and base64_encode encode the sequence of bytes and do not generate a hash like sha1 or md5.
bin2hex just converts every character in the string to its hex value and as for base64, check the wikipedia article to see exactly why the string is the same for large part of the outcome
你的“哈希”在我指出的地方是不同的。 bin2hex 不是加密或散列,它只是获取输入字符串的每个字符并将其转换为其十六进制 ascii 代码的字符串版本。
Your "hashes" are different at the spot I've indicated. bin2hex isn't encryption or hashing, it simply takes each character of the input string and converts it into the string version of its hexadecimal ascii code.