Learn how to secure networks, applications, and systems against digital threats.
Cryptography is the science of protecting information by transforming it. It gives us confidentiality (encryption), integrity (hashing and signatures), and authenticity (signatures and certificates). This lesson explains the fundamental ideas — encryption versus hashing, symmetric versus asymmetric encryption, password hashing, digital signatures, and the public-key infrastructure behind HTTPS. The most important skill is knowing which tool to use when: hash passwords, encrypt data, sign messages. Confusing these is the source of most cryptographic mistakes.
| Encryption | Hashing | Encoding | |
|---|---|---|---|
| Reversible? | Yes (with the key) | No (one-way) | Yes (deterministic) |
| Purpose | Confidentiality | Integrity / verification | Representation |
| Example | AES, RSA | SHA-256, bcrypt | Base64, hex |
Symmetric encryption uses one shared key to both encrypt and decrypt. It is fast and used for bulk data. AES is the standard algorithm. The challenge is securely sharing the key.
Asymmetric encryption uses a key pair: a public key (shared freely) and a private key (kept secret). Anything encrypted with the public key can only be decrypted with the private key. RSA is the classic example. It solves key distribution but is slower.
A hash function maps any input to a fixed-size output and is one-way and deterministic. The same input always gives the same hash, but you cannot recover the input from the hash. SHA-256 is a common example.
Passwords must never be stored in plaintext or encrypted — they must be hashed with a slow, salted algorithm. A salt is random data added before hashing so identical passwords produce different hashes. bcrypt and Argon2 are designed to be slow, making brute-force attacks expensive.
A digital signature is created with a private key and verified with the corresponding public key. It proves authenticity and integrity: the message came from the key holder and was not altered.
TLS uses asymmetric cryptography to establish a session key, then symmetric encryption for the rest of the connection. This gives the security of asymmetric with the speed of symmetric.
A digital certificate binds a public key to an identity. A Certificate Authority (CA) signs certificates, and browsers trust a set of root CAs. A certificate chain links a site’s certificate up to a trusted root.
SHA-256 is a fast hash for integrity, not for password storage. For passwords use a slow salted algorithm such as bcrypt or Argon2 (not shown here because the sandbox uses only the standard library).
The same input always produces the same hash; you cannot reverse it.
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
The avalanche effect: one different character produces a completely different digest.
2cf24dba5fb0a30e 185f8db32271fe25