Hashlib
The `hashlib` module provides secure hash and message digest algorithms. It is essential for password storage, data integrity verification, and cryptographic applications. The guide walks through Hashing Basics, Password Hashing, Hashing Files, Keyed Hashing (HMAC). Create a hash object: `h = hashlib.sha256()`. Update with data: `h.update(b"Hello")`. Get digest: `h.hexdigest()` returns a hex string, `h.digest()` returns bytes. Common algorithms: `md5()`, `sha1()`, `sha256()`, `sha512()`, `blake2b()`. Always use SHA-256 or stronger for security. MD5 and SHA-1 are deprecated for security use due to collision vulnerabilities. NEVER hash passwords with plain SHA — use a slow, salted algorithm like bcrypt, scrypt, or Argon2. The `hashlib` module alone is not sufficient. Use `bcrypt` library: `password = bcrypt.hashpw(password_bytes, bcrypt.gensalt())`. Verify: `bcrypt.checkpw(input_bytes, stored_hash)`. Argon2 (via `argon2-cffi`) is the modern standard for password hashing. Hash large files in chunks to avoid memory issues: `sha256 = hashlib.sha256(); while True: chunk = f.read(8192); if not chunk: break; sha256.update(chunk)`. Compare checksums: download SHA-256 from source and verify `computed == expected`. Use `hashlib.file_digest(file, "sha256")` in Python 3.11+ for convenient file hashing.