如果文件长度相同,哈希冲突的可能性有多大?
我正在设计一个文件服务器应用程序,我想检查客户端计算机上的缓存文件是否是服务器上保存的最后版本。
我不太信任文件系统中的“更改日期”属性,因此我想比较文件中的实际字节。
我认为最快的方法(因为通过网络发送所有字节需要一些时间)是将文件长度和哈希字节发送到服务器。然后服务器首先检查文件长度,如果匹配,则计算位于服务器上的文件的哈希值,然后检查它是否与客户端计算的相同。
谁能告诉我当文件大小相同时哈希冲突的可能性有多大? (我目前使用 MD5 是因为它的速度)。
我可以假设如果文件大小相同并且哈希值相同,内容也相同吗?
谢谢!
I am designing a file-server application where I want to check if a cached file on a client computer is the last version who is kept on the server.
I don't quite trust the 'changed date' attribute in the file system, so I want to compare the actual bytes in the file.
I think the fastest way to do this (as sending all the bytes across the web takes some time), is to send the file length and hash bytes to the server. Then the server checks the file length first, and if they match, it computes a hash for the file located on the server, and then checks if it is the same that the client computed.
Can anybody tell me what the how probable the hash collisions are when the file size is the same? (I am currently using MD5 for its speed).
Can I assume if the file size is the same and the hash is the same that the content is the same?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MD5 中随机碰撞的可能性非常小,因此几乎可以肯定忽略这种可能性是安全的。
然而,MD5 已被证明在加密方面较弱,因此恶意对手可能会故意创建冲突的文件。一个著名的例子是:
来源
Random collisions in MD5 are so improbable that its almost certainly safe to ignore the possibility.
However MD5 has been shown to be cryptographically weak so a malicious adversary could deliberately create files that collide. A famous example is:
Source