Jump to content

calculate crc32 of file in php


robdavies

Recommended Posts

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

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

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.