hashlib
The Python standard-library module that computes stable cryptographic hashes such as SHA-256.
In more detail
Unlike the built-in hash(), hashlib digests are the same on every run and every machine, so they suit identifiers stored in files or sent between processes. You pass bytes, not str, so text is encoded first. It offers SHA-256 and several other standard hash algorithms.
Examples
hashlib.sha256('apple'.encode()).hexdigest()[:16]The course derives a Bloom filter's k positions from SHA-256 by hashing the item with k different prefixes.Related terms
- SHA-256 — A widely used hash function that turns any data into a 256-bit fingerprint, shown as 64 hexadecimal characters.
- hexdigest — A hash result written as a string of hexadecimal characters, returned by the hexdigest() method of a hashlib object.
- hash function — A function that turns data of any size into a fixed-size value, called its hash, used to find items quickly in a table or to detect any change in the data.
- hash — A short fixed-length fingerprint calculated from data, which changes completely if even one byte of the data changes.
- scrypt — A memory-hard password hashing function that is slow and needs lots of memory, so guessing passwords in bulk is expensive.
- MD5 — An old 128-bit hash function that is completely broken for security and should only be used where no attacker is involved.
Taught in
- What A Hash Function Promises — Algorithms & Data Structures for Working Engineers
- Collisions In Practice And Hash Flooding — Algorithms & Data Structures for Working Engineers
- Authentication Versus Authorisation — Application Security & Threat Modeling for Engineers
- Workload Identity — Application Security & Threat Modeling for Engineers
- Lockfiles And Reproducible Builds — Application Security & Threat Modeling for Engineers
- Provenance And Signing — Application Security & Threat Modeling for Engineers
- Static Application Security Testing — Application Security & Threat Modeling for Engineers