# Cryptography and secrets security * Never implement custom cryptographic primitives. Never use MD5 or SHA-1 for security purposes, DES, 3DES, RC4, ECB mode, or unauthenticated CBC. * Use maintained platform cryptography with authenticated encryption, secure randomness, and verified signatures and certificates. Minimum choices (as of OWASP and NIST guidance in 2025; check current guidance when starting a project): * Symmetric encryption: AES-256-GCM with a unique 96-bit nonce per key and message, never reused, or ChaCha20-Poly1305. * Hashing and MACs: SHA-256 or stronger; HMAC-SHA-256 or stronger. * Signatures and key exchange: Ed25519, ECDSA or ECDH with P-256 or stronger, or RSA with at least 2048 bits (3072 for keys that must stay secure beyond 2030), with RSA-OAEP or RSA-PSS padding. * Transport: TLS 1.2 or newer, TLS 1.3 preferred; never disable certificate or hostname validation. * Keep key generation, storage, access, rotation, revocation, and backup separate from application data where practical. Restrict each key to its intended purpose. * Treat tokens, private keys, connection strings, and credentials as secrets; keep them out of source, URLs, command lines, logs, fixtures, and error messages. Keep server-side credentials out of frontend code; browser handling of user session tokens follows the web security rule. * Use environment-appropriate secret storage, separate environments, and rotate compromised or overexposed credentials. Do not silently fall back to a weaker key or algorithm when configuration is missing. * Compare secret-derived values with established constant-time APIs when the comparison is security-sensitive. * Do not log plaintext or retain decrypted sensitive data longer than required. Apply secure disposal only where the runtime and data type provide meaningful guarantees.