2012-04-20 195 views
3

我需要使用PHP获取文件的CRC64校验和。CRC64文件校验和PHP实现

有了这个代码

file_put_contents('example.txt', 'just an example'); 

echo hash_file('crc32', 'example.txt'); 

我得到CRC32校验 “c8c429fe”;

但我需要使用CRC64算法(

enter image description here

得到校验我把它从这里:http://en.wikipedia.org/wiki/Cyclic_redundancy_check

我如何在PHP中实现这个哈希算法?

+2

退房在http评论://php.net/crc32 ... – deceze 2012-04-20 11:45:03

+0

的[Morfi的(http://stackoverflow.com/a/15831803/6194172 )做工作。但是,您并没有将其标记为解决方案。 – Hakuno 2017-04-02 21:13:43

回答

0

hash_file只是一个将file_get_contents($ file)的结果传递给包装的包装,因此您可以使用任何函数而不是'crc32'。

你必须使用crc64吗?如果你只是想哈希文件,你就会有MD5和SHA在您的处置,这可以作为,否则很容易被用作

$hash = hash_file("sha1", $file); 

,只是让自己crc64实施和

function crc64($string){ 
    // your code here 
} 

$hash = hash_file("crc64", $file); 
+0

谢谢@nyson!是的,我必须使用CRC64,但我无法在PHP中找到这个algorythm的任何实现。 – artaskerov 2012-04-20 12:06:04