CRC32C Checksum Update Chunking

CRC32C update() calls accumulate the same checksum whether input arrives whole or chunked, and flipping one byte changes the value, exposing corruption.

JavaData Integrity

Code

snippet
import java.nio.charset.StandardCharsets;
import java.util.zip.CRC32;
import java.util.zip.CRC32C;
import java.util.zip.Checksum;

public class CorruptionProbe {

    public static void main(String[] args) {
        byte[] payload = "order-sync:v42".getBytes(StandardCharsets.UTF_8);

        Checksum crc32c = new CRC32C(); // Castagnoli 多项式,网络与存储校验常用
        crc32c.update(payload);
        System.out.println("crc32c = " + crc32c.getValue());

        Checksum crc32 = new CRC32(); // 经典 CRC-32:同一输入得到不同校验值
        crc32.update(payload);
        System.out.println("crc32  = " + crc32.getValue());

        // chunking:分段 update 与整段 update 累积出同一结果
        Checksum chunked = new CRC32C();
        chunked.update(payload, 0, 6);
        chunked.update(payload, 6, payload.length - 6);
        System.out.println("chunked = " + chunked.getValue());

        // 翻转一个字节后校验值变化:可用于 detect corruption
        payload[5] ^= 0x01;
        Checksum damaged = new CRC32C();
        damaged.update(payload);
        System.out.println("damaged = " + damaged.getValue());
    }
}

Where the work happens

CRC32C Checksum Update Chunking comes down to the class CorruptionProbe and the function main.

Caveats

  • No dependencies section needed; the standard library is the whole story.

Using it

The callable you reach for: public static void main(String[] args)

Output lines are prefixed (crc32c =, crc32 =, chunked =), so the outcome of every step stays visible.

Key statements

byte[] payload = "order-sync:v42".getBytes(StandardCharsets.UTF_8);
Checksum crc32c = new CRC32C(); // Castagnoli 多项式,网络与存储校验常用
crc32c.update(payload);
Checksum crc32 = new CRC32(); // 经典 CRC-32:同一输入得到不同校验值
crc32.update(payload);

Interactive Tools for This Topic

FAQ

What does CRC32C Checksum Update Chunking print when run?
Execute the whole file; each printed line is prefixed with a label like `crc32c =`, `crc32 =`, `chunked =`.