mcrypt Deprecation — Migrate to OpenSSL
debt(d5/e5/b3/t7)
Closest to 'specialist tool catches it' (d5). The detection_hints list rector and phpcs, both specialist/static-analysis tools that can flag mcrypt_encrypt|mcrypt_decrypt patterns. It won't be caught by a plain compiler error (d1) or a default linter out of the box, but these tools automate detection when configured.
Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix says to replace mcrypt with libsodium or AES-256-GCM, but common_mistakes reveal that a naive one-for-one swap (mcrypt to AES-CBC) is still insecure. A correct migration requires auditing all encryption call sites, changing key/nonce management, and potentially adding HMAC authentication — touching multiple files and requiring careful cryptographic decisions, not just a single-line swap.
Closest to 'localised tax' (b3). The applies_to scope covers both web and cli contexts but is bounded to code that actually uses mcrypt. Once the migration is complete the burden is lifted entirely; it does not persist as an ongoing structural tax on the codebase. The impact is real during migration but does not shape every future change.
Closest to 'serious trap' (t7). The misconception field explicitly states that AES-CBC without authentication is vulnerable to padding oracle attacks, yet CBC is the natural migration target for developers moving from mcrypt. This contradicts the reasonable expectation that 'just use OpenSSL with the same mode' is safe. The common_mistakes confirm developers routinely make this mistake, making it a serious cryptographic trap that contradicts intuition from similar contexts.
TL;DR
Explanation
mcrypt was PHP's encryption extension for decades — but it was unmaintained since 2007, used outdated algorithms, and had a confusing API. PHP 7.1 deprecated it, PHP 7.2 removed it. Migration: AES-256-CBC via openssl_encrypt($data, 'aes-256-cbc', $key, 0, $iv). The correct modern option: libsodium (PHP 7.2+) with sodium_crypto_secretbox() — authenticated encryption preventing tampering. Key management: never hardcode keys, use environment variables or a secrets manager. Always use authenticated encryption (AES-GCM or libsodium) — unauthenticated AES-CBC can be attacked via padding oracle.
Common Misconception
Why It Matters
Common Mistakes
- Migrating from mcrypt to AES-CBC without adding authentication (HMAC) — still vulnerable.
- Not using sodium_crypto_secretbox() which handles key+nonce management correctly.
- Hardcoding encryption keys in source code.
Code Examples
// mcrypt — removed in PHP 7.2:
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_CBC);
// Modern libsodium (PHP 7.2+) — authenticated encryption:
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$key = sodium_crypto_secretbox_keygen();
$encrypted = sodium_crypto_secretbox($data, $nonce, $key);
// Decrypt:
$decrypted = sodium_crypto_secretbox_open($encrypted, $nonce, $key);