Home » Core Java » util » zip » Calculate CRC32 checksum for byte array

### About Byron Kiourtzoglou

Byron is a master software engineer working in the IT and Telecom domains. He is an applications developer in a wide variety of applications/services. He is currently acting as the team leader and technical architect for a proprietary service creation and integration platform for both the IT and Telecom industries in addition to a in-house big data real-time analytics solution. He is always fascinated by SOA, middleware services and mobile development. Byron is co-founder and Executive Editor at Java Code Geeks.

# Calculate CRC32 checksum for byte array

In this example we shall show you how to calculate the CRC32 Checksum of a byte array. To calculate the CRC32 checksum of a byte array one should perform the following steps:

• 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,

as described in the code snippet below.

```package com.javacodegeeks.snippets.core;

import java.util.zip.CRC32;
import java.util.zip.Checksum;

public class CalculateCRC32ChecksumForByteArray {

public static void main(String[] args) {

String input = "Java Code Geeks - Java Examples";

// get bytes from string
byte bytes[] = input.getBytes();

Checksum checksum = new CRC32();

// update the current checksum with the specified array of bytes
checksum.update(bytes, 0, bytes.length);

// get the current checksum value
long checksumValue = checksum.getValue();

System.out.println("CRC32 checksum for input string is: " + checksumValue);

}

}
```

Output:

````CRC32 checksum for input string is: 3564377865`
```

This was an example of how to calculate the CRC32 checksum of a byte array in Java.

# Do you want to know how to develop your skillset to become a Java Rockstar?

## Subscribe to our newsletter to start Rocking right now!

### and many more ....

Subscribe
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Inline Feedbacks