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.
Code
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
ISBN ValidatorValidate ISBN-10 and ISBN-13 identifiers with checksum verification, hyphen-tolerant input, and conversion between the two forms.Luhn Checksum ValidatorValidate numeric identifiers with the Luhn algorithm and see the checksum sum and suggested final digit on failure.RAG Document Chunk VisualizerSplit long documents into RAG chunks by character or word count with configurable overlap, boundary alignment, token stats, and highlighted overlaps.SRI Hash GeneratorGenerate Subresource Integrity (SRI) hashes from resource content using SHA-256, SHA-384, or SHA-512, and copy a ready-to-use script tag.
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 =`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.