Overview Types Algorithms Attacks Tools Demo Best Practices Legal Resources

Cryptography Guide

What is Cryptography?

Cryptography is the practice of securing communication and data using mathematical algorithms (encryption, decryption, hashing, digital signatures). Core goals: confidentiality (data unreadable without key), integrity (data not tampered), authentication (verify sender), non-repudiation (sender cannot deny). Modern cryptography underpins HTTPS (TLS/SSL), VPNs, digital signatures, blockchain, password hashing (bcrypt, Argon2).

Cryptography Statistics: 95% of web traffic uses TLS/SSL (HTTPS). AES-256 is unbroken (military-grade). 2^256 possible keys (more than atoms in universe). Quantum computing threatens RSA-2048 (Shor's algorithm).

95%
Web Traffic Uses TLS
2^256
AES-256 Key Space
2030+
Quantum Threat Timeline

Core cryptographic primitives:

Types of Cryptography

Symmetric Encryption (Secret Key)

Same key for encryption and decryption. Fast (1-10 Gbps). Key distribution problem. Algorithms: AES (AES-128, AES-256, AES-GCM), ChaCha20, DES (broken), 3DES (deprecated).

Most Common

Asymmetric Encryption (Public Key)

Public key encrypts, private key decrypts. Slow (10-100 Mbps). Solves key distribution. Algorithms: RSA (RSA-2048, RSA-4096), ECC (ECDSA, Ed25519, X25519).

Hash Functions (One-Way)

Fixed-size output (256 bits). Collision-resistant, preimage-resistant. Password hashing: bcrypt, Argon2, PBKDF2. Data integrity: SHA-256, SHA-3, BLAKE2, SHA-1 (broken).

Hybrid Encryption

Combine asymmetric + symmetric (TLS/SSL). Asymmetric for key exchange, symmetric for data encryption. Example: RSA + AES.

Cryptographic Algorithms & Standards

// Symmetric encryption (AES-256-GCM - recommended) from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes import os key = os.urandom(32) # 256-bit key iv = os.urandom(12) # 96-bit IV (GCM) cipher = Cipher(algorithms.AES(key), modes.GCM(iv)) encryptor = cipher.encryptor() ciphertext = encryptor.update(b"secret data") + encryptor.finalize() // Asymmetric encryption (RSA-2048 - SSL/TLS) openssl genrsa -out private.pem 2048 openssl rsa -in private.pem -pubout -out public.pem // Hash function (SHA-256) echo -n "password123" | sha256sum // Output: ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f // Password hashing (bcrypt - recommended) import bcrypt salt = bcrypt.gensalt(rounds=12) # Cost factor 12 hashed = bcrypt.hashpw(b"password123", salt) // Digital signature (ECDSA) openssl ecparam -name secp256k1 -genkey -out private.key openssl ec -in private.key -pubout -out public.key

Cryptographic Attacks

Brute Force Attack

Try every possible key. AES-256: 2^256 possibilities (infeasible). Quantum computing (Grover's algorithm) reduces to 2^128 (still infeasible).

Side-Channel Attacks

Timing attack (cache timing, branch prediction), power analysis (SPA, DPA), electromagnetic radiation. Mitigation: constant-time algorithms.

Birthday Attack (Hash Collision)

Find two different inputs with same hash. SHA-1 broken (Google shattered attack, 2020). SHA-256 collision-resistant (2^128 operations).

Man-in-the-Middle (MitM) Attack

Attacker intercepts key exchange (Diffie-Hellman). Mitigation: digital signatures, certificate pinning, TLS with certificate validation.

Quantum Computing Threat (Shor's Algorithm)

Shor's algorithm breaks RSA, ECC (factorization, discrete log). Post-quantum cryptography: Kyber (NIST PQC winner), Dilithium, Falcon, SPHINCS+.

Padding Oracle Attack (CBC mode)

Exploits error messages to decrypt ciphertext. Mitigation: use authenticated encryption (GCM, ChaCha20-Poly1305).

Cryptographic Tools

OpenSSL

TLS/SSL protocol implementation. Generate keys (RSA, ECC), certificates (X.509), encrypt/decrypt files (enc), hash (dgst).

GnuPG (GPG)

OpenPGP implementation. Encrypt/decrypt files, sign/verify signatures, key management (--gen-key, --export, --import).

Hashcat (Password Cracking)

Crack password hashes (MD5, SHA1, bcrypt, NTLM). GPU acceleration (NVIDIA CUDA, AMD OpenCL).

John the Ripper

Password hash cracker (MD5, SHA, bcrypt, NTLM, Kerberos). Wordlist mode, incremental mode.

Cryptography.io (Python Library)

High-level Python cryptography library (AES, RSA, ECDSA, X.509).

Cryptography Simulation (AES-256 Encryption)

This demonstration simulates AES-256 encryption and decryption:

Click "Encrypt & Decrypt" to see AES-256 simulation

This is a simulated demonstration. Real AES-256 is unbroken (military-grade). Use authenticated encryption (AES-GCM, ChaCha20-Poly1305). Never roll your own crypto (use standard libraries).

Cryptographic Best Practices

Use Standard Algorithms (AES-256-GCM)

Use AES-256-GCM (authenticated encryption) instead of AES-CBC. Never use DES, 3DES, RC4, MD5, SHA-1 (broken).

Most Effective

Use Proper Key Management (KMS, HSM)

Store keys in KMS (AWS KMS, Azure Key Vault) or HSM (Hardware Security Module). Never hardcode keys in source code.

Use Secure Password Hashing (bcrypt, Argon2)

Use bcrypt (cost factor 12+), Argon2id (recommended for new systems). Never use MD5 or SHA1 for passwords.

Use Constant-Time Algorithms (Prevent Timing Attacks)

Use constant-time comparison (crypto.timingSafeEqual). Avoid branching based on secret data.

Best Practice - Use Standard Algorithms + Proper Key Management: Use AES-256-GCM (authenticated encryption) or ChaCha20-Poly1305. Use Argon2id or bcrypt for password hashing. Use TLS 1.3 (disable TLS 1.0, 1.1). Store keys in KMS/HSM (AWS KMS, Azure Key Vault). Never roll your own crypto (use libsodium, OpenSSL, cryptography.io).

Further Resources

NIST Cryptographic Standards (FIPS 140-3)

US government cryptographic standards (AES, SHA, RSA, ECDSA, key management).

libsodium (Modern Crypto Library)

High-level cryptographic library (AES-256-GCM, ChaCha20-Poly1305, Argon2, Ed25519).

Crypto 101 (Introductory Book)

Free introduction to cryptography (symmetric, asymmetric, hash, TLS).

← Back to Knowledge Base