Hashing

26 entries

crc32 Function The CRC-32 checksum (IEEE 802.3 polynomial 0xEDB88320) — checksums detect transmission corruption, not tampering, a different tool from the md5/sha cryptographic hash family; languages without a built-in implement the classic table-driven algorithm. crypt Function The low-level crypt(3) one-way hash: the salt prefix selects the algorithm (DES/MD5/bcrypt/SHA-256/512) and the hash string is self-describing; demonstrates deterministic output with a fixed salt plus prefix identification - best practice is the password_hash wrapper. hash Function Generic hashing entry: computes a digest by algorithm name (e.g. sha256) and returns lowercase hex. hash_algos Function Returns the list of registered hashing algorithms in the current environment. hash_equals Function Timing-safe (constant-time) string comparison to prevent timing attacks — the mandatory way to compare MACs, hashes and tokens. hash_hkdf Function HKDF key derivation (RFC 5869: extract to a pseudorandom key, then expand to length) — pairs with hash_pbkdf2: slow PBKDF2 for passwords, fast HKDF for keys. hash_hmac Function Computes a keyed digest of a message with HMAC (Hash-based Message Authentication Code) using the given algorithm. hash_pbkdf2 Function Runs PBKDF2 key derivation and returns the key at the requested length as hex or binary. hash_update Function Pushes data into a streaming hash context, allowing chunked feeding of large files without memory overhead. hash_update_file Function Streams a file into a running hash context (the file version of the hash_init three-step): constant memory, the standard way to digest large files; on failure it returns false and leaves the context usable. md5 Function Computes the MD5 digest of a string as 32 lowercase hex characters (cryptographically broken; checksum uses only). openssl_encrypt Function Authenticated encryption with AES-256-GCM: a walkthrough of openssl_encrypt's tag/aad parameters ($passphrase is really the raw key); failed verification makes openssl_decrypt return false. Asymmetric Sign & Verify Function RSA PKCS#1 v1.5 sign and verify: with a fixed key the signature is deterministic (SHA-256 digest + deterministic padding) and byte-identical across implementations. Alongside Ed25519 (sodium_crypto_sign) it marks the two signature worlds — RSA vs modern curves. password_get_info Function Parses a password hash's prefix metadata (algo ID/algoName/cost...) without verifying the hash; this completes the password_hash/verify/needs_rehash/get_info quartet. password_hash Function Creates a one-way password hash (bcrypt by default: automatic random salt, deliberately slow); this entry demos the paired password_verify check on a fixed hash to keep output deterministic. password_needs_rehash Function Password-hash upgrade detection: the stored hash string is self-describing metadata (parse the $2y$12$ prefix) - rehash on login when the algorithm or cost no longer matches; the third piece of the password family. password_verify Function Checks whether a password matches the hash string produced by password_hash, returning true/false. sha1 Function Computes the SHA-1 digest of a string as 40 lowercase hex characters (broken by practical collision attacks; not for security). Authenticated Public-Key Encryption Function Public-key encryption (X25519 key agreement + XSalsa20-Poly1305): the sender encrypts with the recipient's public key and only the matching private key decrypts. The counterpart to symmetric secretbox — box = key agreement + secretbox. sodium_crypto_ipcrypt_* Function Reversible IP-address encryption (new in PHP 8.6, Sodium): the ipcrypt spec's four modes — deterministic (single AES block, same input same ciphertext), nd (random nonce), ndx (extended nonce), pfx (prefix-preserving) — de-identified logs that stay traceable. Argon2id Password-Derived Keys Function Derive a key from a password (Argon2id, memory-hard): with a fixed salt and parameters the derived key is deterministic and interoperable. A triangle with PBKDF2 (hash_pbkdf2) and bcrypt (password_hash) — memory hardness is the modern bar. sodium_crypto_secretbox Function Authenticated encryption with a shared key: XSalsa20-Poly1305 produces a 16-byte MAC followed by the ciphertext; decryption returns false when the tag does not verify. Streaming AEAD Function Streaming AEAD for large files: one 24-byte header plus per-chunk push/pull, each chunk carrying a tag (MESSAGE/FINAL/PUSH/REKEY), state evolving with the ciphertext — tamper any chunk and the stream dies. The counterpart to one-shot secretbox. sodium_crypto_sign Function Ed25519 digital signatures (deterministic: same key and message always produce the same signature); returns signature || message, and failed verification surfaces as sign_open returning false. sodium_crypto_xof_shake256 Function SHAKE256 extendable-output function (new in PHP 8.6, Sodium): squeeze any output length on demand from the same input; length comes first. sodium_crypto_kem_* Function Post-quantum key encapsulation (new in PHP 8.6, Sodium): an X-Wing hybrid family (ML-KEM-768 + X25519) and a pure-PQ ML-KEM-768 family (FIPS 203) with identical workflows — enc produces [ciphertext, shared secret], dec recovers the same secret.