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

Encryption Laravel Package

spaze/encryption

spaze/encryption is a lightweight PHP library for symmetric encryption, offering a simple API to encrypt and decrypt strings and application data using secure cryptographic primitives, with key handling that fits easily into existing PHP projects.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

  • Architecture fit: The package remains a good fit for Laravel applications that need application-level encryption, field-level protection, or controlled ciphertext exchange between services. v3.0.0 materially improves fit for multi-party and asymmetric use cases: AuthenticatedPublicKeyEncryption supports bidirectional encrypted exchange with sender authentication, while AnonymousPublicKeyEncryption supports write-only producers that hold only public keys. This is useful for ingest pipelines, partner integrations, telemetry collection, and services that must encrypt but must not be able to decrypt.
  • Integration feasibility: Greenfield adoption is straightforward for teams already using Laravel config/service patterns. Brownfield adoption is materially harder because v3 writes a marked format that older package versions cannot read. Any environment that shares ciphertext must be upgraded before any v3 writes occur. The Halite requirement moves from 5.0 to 5.1+, so dependency resolution and PHP/ext-sodium compatibility should be checked early. Exception handling also needs review because FormatMarkerMismatchException and UnknownFormatMarkerException replace Halite exceptions for format errors.
  • Technical risk: The primary risk is mixed-version deployment. If one writer starts producing $keyId$... marked values before every reader is on v3, those readers will fail. Rollback after v3 writes is also risky because older versions cannot decrypt the new format. The re-encryption sweep is another risk: needsReEncrypt() now returns true for all pre-v3 values, so a broad sweep will touch all existing encrypted data; rows written with encryptWithAd() must be re-encrypted with the correct row additional data or decryption will fail. Asymmetric key handling introduces operational risk: a missing private key makes anonymous ciphertext unrecoverable by design, and a mismatched or missing key pair should fail at object creation, which is good but must be validated during deployment.
  • Key questions: Which deployments, services, queues, and jobs read or write shared ciphertext? Can all readers be upgraded before any writer emits v3 values? Are all catch blocks updated for the new exception types? Is there a tested re-encryption plan that includes additional-data rows? How will public/private keys be provisioned, stored, rotated, and audited? Do write-only producers truly need no decrypt path, and is that acceptable to the business? What is the rollback plan if v3 writes begin before all readers are ready?

Integration Approach

  • Stack fit: Integrate through Laravel configuration and dependency injection, keeping key material in environment/secret management rather than source control. Use the tagged key forms prefix_secret_hex and prefix_public_hex where asymmetric keys are used so a key pasted into the wrong slot fails during object creation. Use AuthenticatedPublicKeyEncryption for two-party exchanges where both sides encrypt/decrypt and need sender authentication. Use AnonymousPublicKeyEncryption only for producer-only workflows where the writer should never be able to read back ciphertext.
  • Migration path: Treat this as a coordinated format migration, not a routine dependency bump. First inventory every reader and writer of encrypted data, including queues, scheduled jobs, exports, analytics jobs, and external partners. Upgrade all readers to v3 and update exception handling before enabling v3 writes. Then enable new writes, run the needsReEncrypt() sweep, and verify old and new values decrypt correctly. For encryptWithAd() rows, include the row’s additional data during re-encryption.
  • Compatibility: v3 can read old and new values; older versions cannot read marked values. Therefore all deployments sharing data must be upgraded before new writes. Update code that catches Halite InvalidMessage or InvalidNumberOfComponentsException so it also handles FormatMarkerMismatchException and UnknownFormatMarkerException. Confirm paragonie/halite 5.1+ resolves cleanly and that key casing is handled correctly; the release notes document keys as valid in lowercase or uppercase. Test decryption of legacy fixtures before enabling writes.
  • Sequencing: 1) Upgrade dependency constraints and application code in a non-writing environment. 2) Update exception handling and key configuration, including tagged asymmetric key slots. 3) Deploy v3 read-compatible code to every deployment that may encounter ciphertext, but do not write new-format values yet. 4) Validate key pairs and old-format decryption. 5) Enable v3 writes. 6) Run a throttled re-encryption sweep and monitor failures. 7) Confirm all values are migrated and remove legacy-format assumptions. If all deployments cannot be coordinated, delay v3 writes until they can.

Operational Impact

  • Maintenance: Key lifecycle management becomes more complex because asymmetric keys add public/private key distribution and rotation concerns. Establish ownership for key generation, storage, rotation, and revocation. The new marker system reduces support ambiguity by naming the class and method that created a value, but it also creates a new format distinction that on-call staff must understand. Keep Halite and sodium extensions current.
  • Support: Update runbooks for the new exception types and for distinguishing legacy values from marked values. The shortened, printable key IDs and markers reduce the risk of leaking key material or garbage into logs, which is helpful. Support teams will need clear guidance that AnonymousPublicKeyEncryption data cannot be decrypted by the producer and that lost private keys mean unrecoverable data by design. Re-encryption jobs need dashboards and alerting.
  • Scaling: Marker parsing overhead should be negligible. Asymmetric encryption is likely more expensive than symmetric encryption, so high-volume ingest should be benchmarked before broad rollout. Write-only deployments can scale without private keys, which is an architectural advantage. Re-encryption sweeps can be I/O- and CPU-intensive; throttle them and run them off-peak. Key lookup and configuration should be cached where the package supports it.
  • Failure modes: The most serious failure is a mixed-version fleet where v3 writes before all readers upgrade, making new ciphertext unreadable to old readers. Rollback after v3 writes has the same effect. Old catch blocks will miss FormatMarkerMismatchException and UnknownFormatMarkerException. Re-encrypting additional-data rows without the correct additional data will produce undecryptable values. Tampered markers, stripped markers, or forged markers should fail decryption, which is desirable but will surface as application errors if data is corrupted. The old-format key-ID tamper caveat remains only for values in the old format.
  • Ramp-up: Greenfield teams can ramp quickly with standard Laravel integration and documentation. Existing multi-deployment teams need a security review, key-management training, migration rehearsal, and on-call preparation. Plan a staged rollout starting with non-critical data, then critical data after the re-encryption sweep and exception handling are proven. Expect moderate effort for greenfield adoption and high coordination effort for shared-data brownfield environments.
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.
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
cgv/localized-resource