How to Calculate CRC32 Checksum in Java


In this example we will show how to get the CRC32 checksum value for array of bytes using CRC32 class in Java.

Source Code

package com.beginner.examples;

import java.util.zip.CRC32;
import java.util.zip.Checksum;
 
public class CRC32Example {
	
	public static void main(String args[]){
		
		String str = "string example";
		
		//Convert string to bytes
		byte bytes[] = str.getBytes();
		
		Checksum crc32 = new CRC32();
		 
		crc32.update(bytes, 0, bytes.length);
		//get crc32 check number
		long checknum = crc32.getValue();
		
		System.out.println("CRC32 checknum is : " + checknum);
	}
 
}

Output:

CRC32 checknum is : 600486020

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments