Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Legacy Encrypter Laravel Package

laravel/legacy-encrypter

Drop-in Laravel encrypter compatible with legacy apps. Encrypt/decrypt data using older key formats and cipher settings so you can read existing payloads and migrate safely. Useful for upgrades where stored encrypted values must remain accessible.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Purpose Alignment: The legacy-encrypter package is designed to replicate the deprecated mcrypt-based encryption behavior in Laravel (pre-Laravel 8.x). It is a drop-in replacement for the removed mcrypt driver, ensuring backward compatibility for legacy systems still using this encryption method.
  • Use Case Justification:
    • Ideal for migrating legacy applications from mcrypt to Laravel’s modern encryption stack (e.g., OpenSSL).
    • Useful for maintaining encrypted data in databases or storage where mcrypt was previously used, without requiring a full re-encryption effort.
    • Not recommended for new projects; modern alternatives (e.g., openssl, defuse/php-encryption) should be preferred.
  • Key Technical Constraints:
    • Deprecation Risk: mcrypt is obsolete (removed in PHP 7.2+), and this package is a temporary bridge. Long-term reliance introduces security and maintenance risks.
    • Performance Overhead: mcrypt is slower and less secure than modern alternatives (e.g., AES-256 via OpenSSL).
    • Key Management: Legacy systems may lack proper key rotation or secure key storage practices.

Integration Feasibility

  • Ease of Adoption:
    • Minimal Code Changes: Replace config/app.php encryption driver from 'mcrypt' to 'legacy-encrypter' and install the package via Composer.
    • API Compatibility: Mimics Laravel’s Illuminate\Encryption\Encrypter interface, so existing encryption/decryption logic (e.g., Crypt::encrypt()) remains unchanged.
  • Dependencies:
    • Requires PHP 7.4+ (Laravel 8+ compatibility).
    • No external dependencies beyond Laravel’s core.
  • Testing Complexity:
    • Unit Tests: Easily verifiable by comparing outputs with a known mcrypt-encrypted payload.
    • Integration Tests: Critical to validate legacy data decryption (e.g., database records, API responses).
    • Edge Cases: Test with malformed/missing IVs, corrupted data, or edge-case payloads (e.g., empty strings).

Technical Risk

  • Security Risks:
    • Weak Encryption: mcrypt uses outdated algorithms (e.g., rijndael-128, rijndael-256) vulnerable to attacks like Sweet32 or BEAST.
    • Key Derivation: Legacy mcrypt implementations may use insecure key stretching (e.g., no PBKDF2).
    • Mitigation: Use this only as a temporary migration tool; re-encrypt data to a modern system ASAP.
  • Data Integrity:
    • Risk of decryption failures if legacy data was corrupted or encrypted with non-standard parameters (e.g., custom IVs).
    • No Authenticated Encryption: Unlike OpenSSL, mcrypt lacks HMAC for tamper detection.
  • Future-Proofing:
    • Laravel may deprecate this package once all legacy systems migrate. Plan for a parallel migration to openssl or defuse/php-encryption.

Key Questions for TPM

  1. Migration Strategy:
    • Is this package being used for active decryption (e.g., reading legacy data) or new encryption (risky)?
    • What is the timeline for migrating to a modern encryption system?
  2. Data Sensitivity:
    • What type of data is encrypted (PII, financial, etc.)? Does it require compliance (e.g., GDPR, HIPAA)?
    • Are there audit logs for encryption/decryption events?
  3. Performance Impact:
    • Will the legacy encryption bottleneck API responses or database queries?
    • Are there high-throughput systems (e.g., batch jobs) where this could cause delays?
  4. Key Management:
    • How are encryption keys stored? Are they hardcoded, in environment variables, or a secrets manager?
    • Is there a key rotation process for legacy data?
  5. Testing Coverage:
    • Are there known encrypted payloads to validate decryption?
    • How will corrupted or malformed data be handled?
  6. Deprecation Plan:
    • What triggers a sunset for this package in the roadmap?
    • Are there parallel encryption paths (e.g., dual-write to new/old systems)?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Native Integration: Works seamlessly with Laravel’s Illuminate/Encryption facade (Crypt).
    • Service Providers: Registers as a drop-in replacement for the mcrypt driver.
    • Artisan Commands: No additional CLI tools required; leverages existing Laravel encryption utilities.
  • PHP Version Compatibility:
    • Minimum: PHP 7.4 (Laravel 8+).
    • Recommended: PHP 8.1+ for security updates (though mcrypt itself is still deprecated).
  • Database/Storage:
    • Compatible with any storage backend (MySQL, PostgreSQL, S3, etc.) where mcrypt-encrypted data exists.
    • No Schema Changes: Purely a runtime replacement.

Migration Path

  1. Assessment Phase:
    • Audit all encrypted data sources (DB fields, cache, files) using mcrypt.
    • Identify critical paths (e.g., user sessions, payment data).
  2. Package Installation:
    composer require laravel/legacy-encrypter
    
    Update config/app.php:
    'encryption' => [
        'driver' => 'legacy-encrypter',
        // ... other config (e.g., key, cipher)
    ]
    
  3. Validation Phase:
    • Write integration tests to verify decryption of legacy data.
    • Test edge cases (e.g., empty strings, max-length payloads).
  4. Parallel Migration (Recommended):
    • Implement a dual-writing system:
      • New data encrypted with openssl.
      • Legacy data decrypted with legacy-encrypter and re-encrypted.
    • Example:
      // Decrypt legacy data
      $legacyData = Crypt::decrypt($mcryptPayload);
      
      // Re-encrypt with OpenSSL
      $newData = Crypt::encrypt($legacyData, 'openssl');
      
  5. Sunset Phase:
    • Once all legacy data is migrated, remove the package and switch to openssl.
    • Update tests to use the modern driver exclusively.

Compatibility

  • Laravel Versions:
    • Tested with Laravel 8+; may work with 7.x but not officially supported.
    • Avoid Laravel 9+: Future versions may drop mcrypt compatibility entirely.
  • Cipher Modes:
    • Supports rijndael-128, rijndael-256, and rijndael-192 (default: rijndael-256).
    • IV Handling: Uses a 16-byte random IV prepended to the ciphertext (standard for mcrypt).
  • Key Requirements:
    • 32-byte key (for AES-256 equivalent).
    • Base64-encoded in Laravel’s .env (e.g., APP_KEY=base64:...).

Sequencing

  1. Phase 1: Read-Only Mode (Low Risk):
    • Use only for decrypting existing data (e.g., database migrations).
    • Avoid encrypting new data with this package.
  2. Phase 2: Dual-Write Mode (Medium Risk):
    • Decrypt legacy data → Re-encrypt with openssl → Store both.
    • Gradually phase out legacy data.
  3. Phase 3: Full Migration (High Risk):
    • Remove legacy-encrypter; enforce openssl for all encryption.
    • Rollback Plan: Ensure legacy decryption is still possible during transition.

Operational Impact

Maintenance

  • Package Updates:
    • No Active Development: This is a static legacy package; no new features or bug fixes expected.
    • Security Patches: None anticipated (relies on deprecated mcrypt PHP extension).
  • Dependency Management:
    • Composer Lock: Pin the package version to avoid unexpected updates.
    • PHP Extensions: Ensure php-mcrypt is not installed (this package is a pure-PHP polyfill).
  • Monitoring:
    • Log decryption failures (e.g., corrupted data, wrong key).
    • Track performance metrics (e.g., latency spikes during decryption).

Support

  • Troubleshooting:
    • Common Issues:
      • Decryption Failures: Often due to incorrect IVs or keys. Validate with:
        try {
            $decrypted
        
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport