简体   繁体   English

为什么md5为两个不同的文件名返回相同的哈希值

[英]Why is the md5 returning same hashes for two different file names

I have two video file having different file names.But when I md5 filenames both are returning same hashes. 我有两个视频文件,文件名不同,但是当我的md5文件名都返回相同的哈希值时。 Below are the file names. 以下是文件名。

1. \\test\\downloadvideo\\ans-70055040.hd.mp4 1. \\ test \\ downloadvideo \\ ans-70055040.hd.mp4

2. \\test\\downloadvideo\\ans-70055298.hd.mp4 2. \\ test \\ downloadvideo \\ ans-70055298.hd.mp4

$this->_video_md5 = md5_file("\test\downloadvideo\ans-70055040.hd.mp4");
$this->_videoo_md51 = md5_file("\test\downloadvideo\ans-70055298.hd.mp4");

echo "md5".$this->_video_md5

will return md551f767588587184d13b8c9e6ed550166sh190d2078270d4ea1cb570b1de7 fb890bc761bda9a 将返回md551f767588587184d13b8c9e6ed550166sh190d2078270d4ea1cb570b1de7 fb890bc761bda9a

echo "md5".$this->_videoo_md51 

will return md551f767588587184d13b8c9e6ed550166sh190d2078270d4ea1cb570b1de7 fb890bc761bda9a 将返回md551f767588587184d13b8c9e6ed550166sh190d2078270d4ea1cb570b1de7 fb890bc761bda9a

How can I get two different md5 hashes for the file names. 如何获得两个不同的md5散列作为文件名。

As written above, md5|sha1_file return the hash of the file contents, not including the file's name. 如上所述, md5|sha1_file返回文件内容的哈希,不包括文件名。

A possible "solution" would be to hash the outcome of both the filename and the hash of the file itself, which will be a unique hash again. 一种可能的“解决方案”是对文件名的结果和文件本身的哈希进行哈希处理,这将再次成为唯一的哈希。

Use md5("\\test\\downloadvideo\\ans-70055298.hd.mp4"); 使用md5("\\test\\downloadvideo\\ans-70055298.hd.mp4"); instead of md5_file, if you want to hash the filename, not the contents of the file. 如果要散列文件名而不是文件内容,请使用md5_file代替。

To get different hashes, change the contents of the files, so the files are not identical. 若要获得不同的哈希,请更改文件的内容,以使文件不相同。

If you want to check the filenames only , use md5("filename") and not md5_file("filename") 如果只想检查文件名,请使用md5("filename")而不是md5_file("filename")

Also you don't seem to have quotes around the filename. 另外,文件名周围似乎没有引号。 They should be there! 他们应该在那里! And escape backslashes! 并逃脱反斜线!

So 所以

md5_file(\test\downloadvideo\ans-70055298.hd.mp4);

should be 应该

md5_file("\\test\\downloadvideo\\ans-70055298.hd.mp4");

otherwise, \\t ist interpreted as a tab character . 否则, \\t ist解释为制表符 Due to that, your md5_file get's an invalid filename both times, thus returning the same hash. 因此,您的md5_file获得了无效的文件名,因此返回了相同的哈希值。

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

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