简体   繁体   English

PHP哈希文件,CRC32b或MD5更好?

[英]PHP hashing files, CRC32b or MD5 is better?

I want to hash user uploaded files 我想对用户上传的文件进行哈希处理

then save the hash to db 然后将哈希保存到数据库

this help me prevent duplicate upload files 这可以帮助我防止重复的上传文件

I was wondering which hash algorithm should I use 我想知道应该使用哪种哈希算法

googled someone say crc32b is better and faster then md5 用谷歌搜索某人说crc32b比md5更好,更快

will not have dynamic errors? 会不会有动态错误?

if not use hash_file('crc32b') , or md5_file vs sha1_file ? 如果不使用hash_file('crc32b')md5_file vs sha1_file

A CRC-32 is much faster, and can be used to rule out a match in most cases. CRC-32的速度要快得多,在大多数情况下可以用来排除匹配。 If you get a hit with a CRC, then you can apply a larger signature to check that it really is a match. 如果使用CRC进行匹配,则可以应用较大的签名来检查它是否确实匹配。 Depending on the volume of your traffic, it is quite possible that you will get false-positive matches with just a CRC. 根据流量的大小,很可能仅使用CRC就能得到假阳性匹配。 Use a SHA-256 to check to see if it really is a match, and only reject on the basis of that. 使用SHA-256来检查它是否真的匹配,并且仅在此基础上拒绝。

There is still an extremely small probability that you will get a false-positive with a SHA-256 as well. 您仍然极有可能使用SHA-256获得假阳性。 For your application however, you might just as well accept preventing a user from uploading a genuinely new file in that very rare case. 但是,对于您的应用程序,在这种非常罕见的情况下,您也可以接受阻止用户上传真正全新的文件。

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

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