Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to determine the CRC of a zip file ?

Tags:

java

zip

I am not sure if I got the concept right, but I know that we can verify that the integrity of the files in a zip by getting the CRC values for each entry. However, my question is if I get a zip file, will there be a CRC for it and if so how can I determine that ?

like image 272
Nikhil Das Nomula Avatar asked Jun 21 '13 00:06

Nikhil Das Nomula


People also ask

Does zip have CRC?

A CRC error indicates that some data in your Zip file (. zip or . zipx) is damaged. CRC stands for "cyclic redundancy check".

How do you find the CRC of a file?

Right-click the file you wish to get the CRC-32 for. A context menu appears. Select the CRC SHA submenu entry. Select any of the available algorithms: CRC-32, CRC-64, SHA-1 or SHA-256 to calculate the respective checksum, or select "*" to calculate all of them and additionally BLAKE2sp.

What is CRC-32 in zip file?

The CRC-32 of the ZIP is the calculation of all the bytes (0-13) before, no?


2 Answers

You can use java.util.zip.CRC32 to compute CRC-32 checksum for any data stream.

BufferedInputStream bis = new BufferedInputStream(
                          new FileInputStream(new File("/path/to/file.zip"))); 
int read = 0;
CRC32 checksum = new CRC32();
byte[] buffer = new byte[1024];
while ((read = bis.read(buffer)) != -1) {
    checksum.update(buffer, 0, read);
}
bis.close();
System.out.println ("CRC32 of your zip is: " + checksum.getValue());
like image 167
Ravi K Thapliyal Avatar answered Sep 28 '22 07:09

Ravi K Thapliyal


You can use the checksumCRC32 method from the FileUtils class in org.apache.commons.io package.

like image 39
JHS Avatar answered Sep 28 '22 08:09

JHS