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

Similar Programs Chapter Last Updated
Zip Entry Is Directory Example In Java ZIP 23-04-2016
Create Zip File With CRC32 Checksum In Java ZIP 23-04-2016
Create Zip File With Adler32 Checksum In Java ZIP 23-04-2016
Extract Zip File With Adler32 Checksum In Java ZIP 23-04-2016
Extract File With CRC32 Checksum In Java ZIP 23-04-2016
Adler32 Checksum In Java ZIP 23-04-2016
Read Zip File Checksum Value In Java Example ZIP 20-07-2016
Create Checksum For Zip File In Java ZIP 07-08-2017
Decompress Zip File Using ZipInputStream In Java ZIP 20-07-2016
Read Entries In Zip File In Java Example ZIP 20-07-2016
List The Contents Of Zip File In Java Example ZIP 07-08-2017
Extract Contents Of Zip File In Java Example ZIP 07-08-2017
Zip File Creation In Java Example ZIP 23-06-2016

1