CRC32 Checksum In Java
Chapter:
ZIP
Last Updated:
10-08-2016 16:41:38 UTC
Program:
/* ............... START ............... */
import java.util.zip.CRC32;
import java.util.zip.Checksum;
public class JavaCRC32CheckSum {
public static void main(String args[]) {
String string = "CRC32 Checksum For Byte Array";
// Convert string to bytes
byte bytes[] = string.getBytes();
Checksum checksum = new CRC32();
checksum.update(bytes, 0, bytes.length);
long lngChecksum = checksum.getValue();
System.out.println("CRC32 checksum for byte array:" + lngChecksum);
}
}
/* ............... END ............... */
Output
CRC32 checksum for byte array:2300509473
Notes:
-
Get the byte array of a String, using getBytes() API method of String.
- Create a new Checksum object, that represents a data checksum.
- Update the current checksum with the specified array of bytes, using update(byte[] b, int off, int len) API method of Checksum.
- Get the current checksum long value, using getValue() API method of Checksum.
Tags
CRC32 Checksum, Java