all Python 3binasciifunction
binascii.crc32()
checksums
Computes the CRC-32 of bytes, an unsigned 32-bit number as in ZIP. The second argument continues a running checksum, so a file can be processed in chunks.
Syntax
binascii.crc32(data[, value])
CRC catches accidental corruption, not tampering: crafting data with a chosen checksum is easy, so integrity against an attacker needs hashlib.sha256. It matches zlib.crc32. For a stream pass the running value along: crc = crc32(chunk, crc). In Python 2 the result could be negative, hence '& 0xffffffff' in old code; Python 3 does not need it.
Examples
import binascii
print(binascii.crc32(b'hello world')) # → 222957957
crc = binascii.crc32(b'hello')
crc = binascii.crc32(b' world', crc)
print(f'{crc:#010x}') # → 0x0d4a1185
See also
Open in the full glossarydocs.python.orgReport an inaccuracy