robdavies Posted April 28, 2007 Share Posted April 28, 2007 Hi I am having a problem calculating a crc32 hash of a file in php. I have uploaded a file, calculated an md5 hash and it is correct, both using md5_file() and hash_file("md5",filename) and they are both correct (tested with md5 command on osx and MD5 in Java). I am using hash_file("crc32",filename) and this gives a different result to crc32 in Java and crc32 command on osx. Can anyone help? Thanks, Rob Link to comment https://forums.phpfreaks.com/topic/49052-calculate-crc32-of-file-in-php/ Share on other sites More sharing options...
heckenschutze Posted April 28, 2007 Share Posted April 28, 2007 Make sure Java and osx aren't using crc32b... You also might want to set the 3rd arg to true ? To get raw binary data, eg hash_file("crc32", $filename, TRUE); Link to comment https://forums.phpfreaks.com/topic/49052-calculate-crc32-of-file-in-php/#findComment-240345 Share on other sites More sharing options...
robdavies Posted April 28, 2007 Author Share Posted April 28, 2007 Thanks, I tried that and now I get the hashes, though in a different order. For one file, Java and osx crc32 are returning 591be178 , however hash_file("crc32b",filename) is returning 78e11b59. To me is looks like the same hash with the pairs of digits in reverse order. I have been running this with different files and get the same results, same hash though in reverse order. Any ideas why this would be? Seems like Java's CRC32 class is generating CRC32b, same as osx' crc32 command. Thanks, Rob Link to comment https://forums.phpfreaks.com/topic/49052-calculate-crc32-of-file-in-php/#findComment-240391 Share on other sites More sharing options...
heckenschutze Posted April 28, 2007 Share Posted April 28, 2007 Try hash_file("crc32b", $filename, TRUE); then ? Well, I think its a combo of not being in binary-mode (with hash_file() and using the wrong alg (crc32 not crc32b)... Remember if you hash a string in the terminal (with mac-os crc32) then your probably hashing something different to what's in the file (eg missing out on new lines, etc)... Just try a few different combos. Link to comment https://forums.phpfreaks.com/topic/49052-calculate-crc32-of-file-in-php/#findComment-240392 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.