数据索引的最佳哈希算法(即crc)(Best hash algorithm for a data index (ie, crc))

编程入门 行业动态 更新时间:2024-10-11 19:24:03
数据索引的最佳哈希算法(即crc)(Best hash algorithm for a data index (ie, crc))

基本上,我正在跟踪文件修改,例如:

array ( 'crc-of-file' => 'latest-file-contents' )

这是因为我在运行时同时处理不同文件的文件内容。

所以,问题是,我应该在文件内容上使用什么哈希算法(作为字符串,因为文件正在被加载)?

防止碰撞是至关重要的,也是至关重要的。 到目前为止,我没有看到任何安全隐患。

编辑:我可以使用的另一件事而不是散列内容是文件修改时间戳,但我不确定它是多么可靠。 另一方面,我认为监控所述邮票比每次散列文件更快。

Basically, I'm keeping track of file modifications, in something like:

array ( 'crc-of-file' => 'latest-file-contents' )

This is because I'm working on the file contents of different files at runtime at the same time.

So, the question is, what hashing algorithm should I use over the file contents (as a string, since the file is being loaded anyway)?

Collision prevention is crucial, as well as performance. I don't see any security implications in this so far.

Edit: Another thing I could have used instead of hashing contents is the file modification timestamp, but I wasn't sure how reliable it is. On the other hand, I think it's faster to monitor the said stamp than hashing the file each time.

最满意答案

CRC它不是哈希算法,也不是校验和算法,所以你的碰撞几率会很高。

md5非常快,碰撞风险对于您的应用/体积来说相当小。 如果要缓冲文件,您可能还希望使用hash扩展来查看增量散列 。

有点复杂,但也值得一看(如果你有的话)是Inotify扩展 。

CRC it's not a hashing algorithm, a checksum algorithm so your chances of collision will be quite high.

md5 is quite fast and the collision risk is rather minimal for your kind of application / volume. If you are buffering the file, you may also want to look at incremental hashes using the hash extension.

A bit more complex, but also worth looking at (if you have it) is the Inotify extension.

更多推荐

本文发布于:2023-08-03 09:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1386265.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法   索引   数据   crc   index

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!