Weave 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

Encrypted Laravel Package

crudly/encrypted

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The crudly/encrypted package provides Eloquent model encryption via Laravel's attribute casting, making it ideal for:
    • Sensitive data (PII, financials, API keys) in relational databases.
    • Compliance-driven projects (GDPR, HIPAA) requiring field-level encryption.
    • Multi-tenant SaaS architectures where tenant isolation is critical.
  • Laravel Synergy: Leverages Laravel’s built-in casting system, reducing boilerplate and aligning with existing Eloquent patterns.
  • Limitation: Not a full database-level encryption solution (e.g., TDE or column-level encryption). Best suited for application-layer encryption.

Integration Feasibility

  • Minimal Overhead: Requires only use declaration and model attribute configuration (e.g., protected $casts = ['ssn' => Encrypted::class]).
  • Dependency: Requires PHP 8.1+ and Laravel 9+ (due to attribute casting improvements).
  • Database Agnostic: Works with MySQL, PostgreSQL, SQLite, etc., but encryption keys must be managed externally (e.g., Laravel’s .env or a secrets manager).

Technical Risk

  • Key Management: Misconfigured encryption keys (e.g., hardcoded) could lead to data loss. Requires integration with a secure key management system (e.g., AWS KMS, HashiCorp Vault).
  • Performance Impact: Encryption/decryption adds CPU overhead. Benchmarking required for high-throughput systems (e.g., >10K RPS).
  • Migration Complexity: Existing encrypted data cannot be "decrypted" post-integration without a migration script.
  • Query Limitations: Encrypted fields cannot be used in WHERE, JOIN, or ORDER BY clauses without additional logic (e.g., application-side filtering).

Key Questions

  1. Compliance Requirements:
    • Does the project mandate field-level encryption (e.g., for PCI DSS or GDPR)?
    • Are there specific algorithms/key lengths required (e.g., AES-256-GCM)?
  2. Key Management:
    • How will encryption keys be stored and rotated? (e.g., environment variables, KMS, or a custom solution?)
  3. Performance:
    • What is the acceptable latency budget for encrypted field access?
    • Are there plans to cache decrypted values (e.g., via Laravel’s cache layer)?
  4. Query Patterns:
    • Are encrypted fields used in database queries? If so, how will filtering be handled?
  5. Backup/Recovery:
    • How will encrypted backups be managed? (e.g., encrypted backups of encrypted data?)
  6. Team Expertise:
    • Does the team have experience with cryptographic best practices (e.g., IV generation, key derivation)?

Integration Approach

Stack Fit

  • Laravel Ecosystem: Seamless integration with Eloquent models, migrations, and API resources.
  • PHP Version: Requires PHP 8.1+ (for named arguments in casting). Verify compatibility with existing PHP extensions (e.g., openssl).
  • Database Drivers: Tested with PDO-based databases. No known conflicts with Laravel’s query builder.
  • Caching: Works alongside Laravel’s cache (e.g., Redis) for decrypted attribute caching.

Migration Path

  1. Assessment Phase:
    • Audit models to identify sensitive fields requiring encryption.
    • Document existing query patterns involving these fields.
  2. Implementation:
    • Add package via Composer: composer require crudly/encrypted.
    • Configure encryption keys in .env (e.g., ENCRYPTION_KEY=base64:...).
    • Update models with Encrypted cast (e.g., protected $casts = ['credit_card' => Encrypted::class]).
    • For existing data, create a migration to re-encrypt fields using a one-time script:
      $users = User::all();
      foreach ($users as $user) {
          $user->forceFill(['credit_card' => $user->credit_card])->save();
      }
      
  3. Testing:
    • Unit tests for model serialization/deserialization.
    • Integration tests for API endpoints exposing encrypted fields.
    • Performance tests under load (e.g., using Laravel Dusk or Pest).

Compatibility

  • Laravel Versions: Officially supports Laravel 9+. Test with 10.x for compatibility.
  • Package Conflicts: Check for conflicts with other encryption packages (e.g., spatie/laravel-encryption).
  • Custom Casts: If using custom casts, ensure they don’t interfere with Encrypted.

Sequencing

  1. Phase 1: Pilot with non-critical models (e.g., user profiles).
  2. Phase 2: Roll out to high-sensitivity models (e.g., payments, health records).
  3. Phase 3: Optimize key management and caching.
  4. Phase 4: Deprecate legacy encryption logic (if applicable).

Operational Impact

Maintenance

  • Dependency Updates: Monitor for breaking changes in Laravel or PHP 8.x.
  • Key Rotation: Implement a cron job or event listener to rotate encryption keys periodically (e.g., quarterly).
  • Package Support: Low maintenance burden; issues can be triaged via GitHub issues.

Support

  • Debugging: Encrypted fields appear as null in Tinker/Artisan if decryption fails. Log decryption errors to track key issues.
  • Documentation: Update internal docs to reflect encrypted field handling (e.g., "API responses may omit sensitive data").
  • User Training: Educate developers on:
    • Avoiding encrypted fields in queries.
    • Using encrypted: prefix in API responses (if needed).

Scaling

  • Horizontal Scaling: Encryption/decryption is stateless; scales with Laravel’s queue workers or caching.
  • Database Load: No direct impact on DB load, but encrypted fields cannot use indexes for queries.
  • Caching Strategy:
    • Cache decrypted values in memory (e.g., Cache::remember) for read-heavy workloads.
    • Example:
      public function getCreditCardAttribute($value) {
          return Cache::remember("user_{$this->id}_credit_card", now()->addHours(1), function() {
              return decrypt($value);
          });
      }
      

Failure Modes

Failure Scenario Impact Mitigation
Lost encryption key Permanent data loss Backup keys in a secure vault (e.g., AWS KMS).
Corrupted encrypted data Field appears as null Regular data integrity checks.
Key rotation without re-encryption Data becomes unreadable Automate re-encryption during rotation.
PHP openssl extension missing Decryption fails Ensure openssl is enabled in PHP-FPM.
High query load on encrypted fields Increased latency Cache decrypted values or offload to queues.

Ramp-Up

  • Onboarding Time: 1–2 days for a Laravel developer to integrate and test.
  • Skills Required:
    • Familiarity with Eloquent and Laravel’s casting system.
    • Basic cryptography concepts (e.g., IVs, key derivation).
  • Training Resources:
  • Handoff:
    • Document key management procedures.
    • Create a runbook for decryption failures (e.g., "If a user’s data appears as null...").
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.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums