phpseclib/mcrypt_compat
PHP 5.x–8.x polyfill for the deprecated mcrypt extension. Provides common ciphers (Rijndael/AES variants, DES, Blowfish, RC2, 3DES, ARCFOUR) and modes (CBC, CFB, CTR, ECB, OFB, stream). Can emulate older PHP mcrypt behavior.
mcrypt extension is unavailable or deprecated. Acts as a drop-in replacement for mcrypt_* functions, enabling seamless migration without rewriting core encryption logic.rijndael-256, tripledes, blowfish) and 7 modes (e.g., cbc, ctr, ecb), making it viable for legacy systems with hardcoded mcrypt dependencies.McryptFacade) to abstract polyfill usage across the app.Illuminate\Encryption) for hybrid systems.mcrypt-encrypted fields (e.g., AES-256-CBC keys).mcrypt.PHPSECLIB_MCRYPT_TARGET_VERSION).extension=mcrypt in php.ini with composer require phpseclib/mcrypt_compat.config/app.php or bootstrap/app.php unless using a facade.mcrypt_encrypt(), mdecrypt_generic(), and mcrypt_get_iv_size() are 1:1 compatible.// Before (fails in PHP 8.x)
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $plaintext, MCRYPT_MODE_CBC, $iv);
// After (polyfill)
$ciphertext = \phpseclib\mcrypt_compat\mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $plaintext, MCRYPT_MODE_CBC, $iv);
// app/Providers/McryptCompatServiceProvider.php
public function boot() {
if (!function_exists('mcrypt_encrypt')) {
\mcrypt_encrypt = \phpseclib\mcrypt_compat\mcrypt_encrypt;
// Alias other functions...
}
}
// app/Facades/Mcrypt.php
public static function encrypt($cipher, $key, $data, $mode, $iv) {
return \phpseclib\mcrypt_compat\mcrypt_encrypt($cipher, $key, $data, $mode, $iv);
}
| Risk | Impact | Mitigation |
|---|---|---|
| Performance Penalty | 10–100x slower than native mcrypt |
Benchmark critical paths; cache results if possible. |
| Behavioral Drift | ncfb mode differs from mcrypt |
Test all edge cases; document deviations in migration notes. |
| Unsupported Algorithms | Cast-128, GOST, etc. not supported | Audit codebase; replace or refactor unsupported algorithms. |
| PHP Version Quirks | Defaults to PHP 7.1 behavior | Use PHPSECLIB_MCRYPT_TARGET_VERSION for legacy systems (e.g., PHP 5.3). |
| Security Debt | RC2, DES, Blowfish are weak | Audit usage; migrate to openssl/sodium post-migration. |
| Deprecation Warnings | PHP 8.2+ may trigger notices | Upgrade to mcrypt_compat v2.0.4+ (includes fixes). |
| Dependency Bloat | Requires phpseclib/phpseclib |
Justify inclusion for legacy systems; avoid for new projects. |
Criticality of mcrypt Usage:
mcrypt calls be replaced with Laravel’s Illuminate\Encryption (uses openssl)?Algorithm Audit:
cast-128, gost)? If so, what’s the migration plan?des, rc2) used in production? If yes, prioritize replacement.Performance Requirements:
mcrypt_compat vs. native mcrypt for their specific workload?PHP Version Support:
mcrypt_compat v2.0.4+ is used.Testing Strategy:
mcrypt-dependent logic? These must be updated to account for behavioral differences (e.g., ncfb mode).Long-Term Roadmap:
mcrypt_compat? Will the team migrate to openssl/sodium post-migration?Security Implications:
mcrypt usage within [X] months?illuminate/encryption, and other Composer packages.phpseclib/phpseclib (≥3.0.36 for v2.x).Illuminate\Encryption (built on openssl).openssl_encrypt() directly.defuse/php-encryption.Phase 1: Assessment (1–2 weeks)
grep or IDE search to find all mcrypt_* function calls.grep -r "mcrypt_" app/ --include="*.php" > mcrypt_usage_report.txt
Phase 2: Dependency Setup (1 day)
composer.json:
"require": {
"phpseclib/mcrypt_compat": "^2.0",
"phpseclib/phpseclib": "^3.0.36"
}
composer update.config/app.php:
'providers' => [
// ...
App\Providers\McryptCompatServiceProvider::class,
],
Phase 3: Configuration (1 day)
// Before autoloading
define('PHPSECLIB_MCRYPT_TARGET_VERSION', '5.3.0');
require __DIR__.'/vendor/autoload.php';
// app/Facades/Mcrypt.php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Mcrypt extends Facade {
protected
How can I help you explore Laravel packages today?