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

Laravel Ciphersweet Laravel Package

spatie/laravel-ciphersweet

Laravel wrapper for Paragonie CipherSweet that adds searchable field-level encryption to Eloquent models. Encrypt/decrypt sensitive attributes and generate blind indexes so you can query encrypted data securely without exposing readable values in your database.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Encryption Paradigm: The package leverages CipherSweet, a field-level encryption library designed for searchable encryption (e.g., encrypted fields can still be queried via plaintext equivalents). This aligns well with Laravel applications requiring GDPR/CCPA compliance or PII protection (e.g., healthcare, finance, or user data).
  • Database Agnostic: Works with MySQL, PostgreSQL, and SQLite (via ciphersweet PHP extension), making it adaptable to most Laravel deployments.
  • Laravel Integration: Provides Eloquent model macros and query builder support, enabling seamless encryption/decryption without manual intervention.
  • Key Management: Supports AWS KMS, HashiCorp Vault, or local key storage, critical for production-grade security.

Integration Feasibility

  • Low Friction: Requires minimal configuration (e.g., config/ciphersweet.php) and integrates with Laravel’s Service Container and Eloquent.
  • Query Flexibility: Encrypted fields can be searched, sorted, and filtered via plaintext equivalents, reducing application-layer logic changes.
  • Performance Overhead: Encryption adds ~10-30ms per field (benchmark-dependent), but CipherSweet’s deterministic encryption (for searchable fields) mitigates repeated hashing costs.

Technical Risk

  • Extension Dependency: Requires the ciphersweet PHP extension (not bundled with PHP), which may need PECL installation or Docker setup.
  • Key Rotation Complexity: Manual key rotation (e.g., for compliance) requires database migrations to re-encrypt data, adding operational overhead.
  • Query Limitations: Complex joins or aggregations on encrypted fields may bypass CipherSweet’s searchability, necessitating application-layer workarounds.
  • Vendor Lock-in: Tight coupling to CipherSweet’s schema (e.g., encrypted_* columns) could complicate future migrations.

Key Questions

  1. Compliance Requirements:
    • Does the project mandate searchable encryption (e.g., for GDPR’s "right to erasure" or HIPAA compliance)?
    • Are there regional data sovereignty laws requiring on-premise key management?
  2. Performance Trade-offs:
    • What’s the acceptable latency for encrypted field operations? (Test with production-like data volumes.)
    • Will deterministic encryption (for searchability) expose patterns in sensitive data?
  3. Key Management:
    • Is AWS KMS/Vault feasible, or must keys be self-hosted? (Self-hosted keys require HSM or secure storage.)
  4. Migration Path:
    • How will existing unencrypted PII be retroactively encrypted? (Batch jobs vs. incremental updates.)
  5. Query Complexity:
    • Are there analytical queries (e.g., GROUP BY, JOIN) that can’t use CipherSweet’s searchable fields?
  6. Monitoring:
    • How will decryption failures (e.g., corrupted keys) be detected and alerted?

Integration Approach

Stack Fit

  • Laravel Ecosystem: Optimized for Laravel 8+ (composer autoloading, Eloquent, Query Builder).
  • Database Support:
    • MySQL/PostgreSQL: Native support via CipherSweet’s pgcrypto/AES functions.
    • SQLite: Limited (requires custom logic for encrypted queries).
  • Caching: Works with Laravel Cache (e.g., Redis) for decrypted field caching, reducing DB load.
  • Testing: Compatible with Pest/Laravel Testing (mock CipherSweet for unit tests).

Migration Path

  1. Assessment Phase:
    • Audit PII fields (e.g., passwords, credit_cards, health_records) for encryption candidates.
    • Identify query patterns that rely on encrypted fields (e.g., WHERE email LIKE '%@gmail.com').
  2. Pilot Phase:
    • Encrypt non-critical fields (e.g., user.bio) first to validate performance.
    • Use deterministic encryption for searchable fields; randomized for non-searchable.
  3. Full Rollout:
    • Database Migration: Add encrypted_* columns via Laravel migrations.
    • Model Updates: Apply CipherSweet::encrypt() macros to Eloquent models.
    • Query Rewriting: Replace raw SQL with CipherSweet’s query builder methods.
  4. Key Management Setup:
    • Configure AWS KMS/Vault or local key storage in config/ciphersweet.php.
    • Implement key rotation via Laravel tasks (e.g., artisan cipher:sweet:rotate).

Compatibility

  • Laravel Versions: Tested on 8.x–10.x; may need adjustments for Lumen (micro-framework).
  • PHP Extensions: Requires ciphersweet extension (PHP 8.0+). Docker example provided in README.
  • Third-Party Packages:
    • Laravel Scout: May need customization for encrypted search.
    • Laravel Nova: Encrypted fields appear as plaintext in UI (workaround: custom tooling).
  • Legacy Systems: If using raw SQL queries, wrap them in DB::select() with CipherSweet’s query methods.

Sequencing

Phase Tasks Dependencies
Prep Install ciphersweet extension, configure Laravel. PHP/Docker setup.
Pilot Encrypt 1–2 non-critical fields; test queries. Database backup.
Core Rollout Encrypt PII fields; update models/queries. Pilot validation.
Key Management Set up KMS/Vault; test key rotation. Encrypted data in production.
Monitoring Log decryption failures; alert on key issues. Full deployment.

Operational Impact

Maintenance

  • Package Updates: Spatie’s package is actively maintained (last release 2026), but CipherSweet’s PHP extension may lag behind PHP versions.
  • Key Rotation:
    • Automated: Use Laravel’s scheduler to run artisan cipher:sweet:rotate.
    • Manual: For custom key storage, implement a cron job to re-encrypt data.
  • Backup Strategy:
    • Encrypted Data: Backups must include keys (or use KMS/Vault snapshots).
    • Key Loss: Requires full data re-encryption (costly for large datasets).

Support

  • Debugging:
    • Decryption Failures: Log CipherSweet\Exceptions\DecryptionFailed events.
    • Query Issues: Use DB::enableQueryLog() to inspect rewritten queries.
  • Documentation:
    • Spatie’s README is comprehensive, but key rotation and query limitations need internal runbooks.
  • Vendor Support:
    • CipherSweet: Community-driven (Paragon IE). For enterprise, consider commercial support.

Scaling

  • Performance:
    • Read-Heavy Workloads: Cache decrypted fields in Redis (TTL-based).
    • Write-Heavy Workloads: Batch encrypt data (e.g., queue jobs for bulk updates).
  • Database Load:
    • Encrypted queries may increase CPU usage (AES operations). Monitor SHOW PROCESSLIST (MySQL) or pg_stat_activity (PostgreSQL).
  • Horizontal Scaling:
    • Stateless Apps: Keys must be shared across instances (e.g., KMS or shared storage).
    • Stateful Apps: Local key storage (e.g., env) requires synchronization.

Failure Modes

Risk Impact Mitigation Strategy
Key Loss/Corruption Permanent data loss. Automated backups of keys; KMS snapshots.
Database Corruption Encrypted data becomes unreadable. Regular backups; test restore procedures.
Query Rewriting Errors Broken searches/filters. Unit tests for encrypted queries.
Extension Misconfiguration Decryption failures. CI checks for ciphersweet extension.
Key Rotation Failures Data becomes unreadable. Dry-run rotations; monitor logs.

Ramp-Up

  • Developer Onboarding:
    • 1–2 Days: Learn CipherSweet’s query syntax and model macros.
    • 1 Week: Pilot encryption for a non-critical feature.
  • Ops Onboarding:
    • Key Management: Train team on KMS/Vault policies and rotation.
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