Hash functions with hashlib
A hash function takes data of any size and returns a fixed-size fingerprint . It is used to detect changes, index data and…
Every program handles data that someone could tamper with or steal. In this lesson you will learn the basic tools of the standard library: hash functions to detect changes, HMAC to sign messages, key derivation with salt to store passwords, Base64, URL and HTML to encode data, and secure randomness and UUID. And, above all, the difference between encoding and encrypting.
A hash function takes data of any size and returns a fixed-size fingerprint . It is used to detect changes, index data and…
A hash detects accidental changes, but anyone can recompute it after tampering with the data. To check also who generated it you…
If a database leaks, whatever is stored in it is exposed. Passwords must be stored so that, even with the database in an…
Encoding changes the representation of some data so a channel can carry it; it hides nothing. Encrypting makes it unreadable…
The random module generates pseudo-random numbers: they look random, but with the same seed they always produce the same…
A hash function turns any data into a fixed-size fingerprint. The same text always gives the same fingerprint, and changing a…
Fingerprints are used to detect that data has changed: the fingerprint is published with the data and whoever receives it…
Base64 represents any bytes with 64 printable characters, so they can be sent through channels that only accept text (email…
Applying XOR with a repeated key is a very weak “cipher”, but it illustrates an important idea: XOR is its own inverse, so the…
A normal hash can be computed by anyone. An HMAC combines the message with a secret key : only someone who knows the key can…
A password must never be stored as is or with a simple hash. What is stored is the result of a slow derivation function such as…
URLs have a precise structure, and splitting them with split or with home-made regular expressions is a classic source of bugs…
If you insert a user's text into an HTML page without escaping it, that text can contain tags or scripts ( XSS injection )…
A UUID is a practically unique 128-bit identifier. Version 4 ones are random; version 5 ones ( uuid5 ) are computed with a hash…
A fast hash and a small secret are a bad combination: if there are only 10,000 possible PINs, an attacker tries them all in…