Skip to main content

Cryptography Cheat Sheet

Hash Functions

AlgorithmOutput SizeStatusUse
MD5128-bitBrokenLegacy only
SHA-1160-bitDeprecatedAvoid
SHA-256256-bitSecureGeneral use
SHA-512512-bitSecureHigh security
bcryptVariableSecurePassword hashing
scryptVariableSecurePassword hashing
Argon2VariableSecure (winner)Password hashing

Hash Identification

32 chars  → MD5
40 chars  → SHA-1
56 chars  → SHA-224
64 chars  → SHA-256
96 chars  → SHA-384
128 chars → SHA-512
$2a$/$2b$ → bcrypt
$6$       → SHA-512crypt (Linux)
$1$       → MD5crypt (Linux)

Hashcat Modes

-m 0     → MD5
-m 100   → SHA-1
-m 1400  → SHA-256
-m 1800  → SHA-512crypt ($6$)
-m 3200  → bcrypt
-m 13100 → Kerberoast (TGS-REP)
-m 18200 → AS-REP Roast
-m 5600  → NetNTLMv2
-m 1000  → NTLM

Symmetric Encryption

Same key for encryption and decryption.

AlgorithmKey SizeBlock SizeStatus
DES56-bit64-bitBroken
3DES112/168-bit64-bitDeprecated
AES-128128-bit128-bitSecure
AES-256256-bit128-bitSecure
ChaCha20256-bitStreamSecure

Block Cipher Modes

ModeNotes
ECBInsecure — same block = same ciphertext
CBCRequires IV, vulnerable to padding oracle
CTRStream mode, parallelizable
GCMAuthenticated encryption (AEAD) — preferred

Asymmetric Encryption

Different keys for encryption (public) and decryption (private).

AlgorithmKey SizeUse
RSA-20482048-bitMin recommended
RSA-40964096-bitHigh security
ECDSA256-bitDigital signatures
Ed25519256-bitSSH keys (preferred)
Diffie-Hellman2048+ bitKey exchange
ECDH256-bitKey exchange

TLS/SSL

TLS Versions

VersionStatus
SSL 2.0Broken — disabled
SSL 3.0Broken (POODLE) — disabled
TLS 1.0Deprecated
TLS 1.1Deprecated
TLS 1.2Acceptable
TLS 1.3Recommended

TLS Handshake (TLS 1.3)

1. Client → Server: ClientHello (supported ciphers, key share)
2. Server → Client: ServerHello + Certificate + Finished
3. Client → Server: Finished
4. Encrypted communication begins

Cipher Suite (TLS 1.2 example)

TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
  │      │    │        │         └── MAC/PRF hash
  │      │    │        └── Encryption + mode
  │      │    └── Authentication
  │      └── Key exchange
  └── Protocol

Testing TLS

# Check certificate
openssl s_client -connect example.com:443

# Check supported protocols
nmap --script ssl-enum-ciphers -p 443 example.com

# Check certificate expiry
openssl s_client -connect example.com:443 2>/dev/null | \
  openssl x509 -noout -dates

# testssl.sh (comprehensive)
./testssl.sh example.com

Password Hashing (Linux)

# /etc/shadow format
$id$salt$hash

# IDs:
$1$  = MD5
$2a$ = Blowfish/bcrypt
$5$  = SHA-256
$6$  = SHA-512 (most common)
$y$  = yescrypt (modern)

# Generate SHA-512 hash
openssl passwd -6 -salt xyz mypassword
python3 -c "import crypt; print(crypt.crypt('pass', crypt.mksalt(crypt.METHOD_SHA512)))"

Common Crypto Attacks

AttackTargetDescription
Brute forceWeak passwords/keysTry all combinations
DictionaryPasswordsTry wordlist
Rainbow tableUnsalted hashesPrecomputed hash table
Birthday attackHash collisionsFind two inputs with same hash
Padding oracleCBC modeDecrypt without key via error messages
BEASTTLS 1.0 CBCExploit CBC IV predictability
POODLESSL 3.0Downgrade + padding oracle
CRIME/BREACHTLS compressionCompression + chosen plaintext
HeartbleedOpenSSLMemory leak via heartbeat extension

OpenSSL Quick Reference

# Generate RSA key pair
openssl genrsa -out private.pem 4096
openssl rsa -in private.pem -pubout -out public.pem

# Generate self-signed cert
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes

# Encode/decode base64
echo "text" | openssl base64
echo "dGV4dA==" | openssl base64 -d

# Hash a file
openssl dgst -sha256 file.txt

# Encrypt/decrypt
openssl enc -aes-256-cbc -in file.txt -out file.enc -k password
openssl enc -d -aes-256-cbc -in file.enc -out file.txt -k password