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.
paragonie/halite and now exposes symmetric authenticated encryption, authenticated public-key encryption, and anonymous public-key encryption behind Laravel-friendly configuration. That is a strong argument for buying/borrowing rather than hand-rolling envelope encryption in application code.AuthenticatedPublicKeyEncryption supports two-way encrypted exchange where each side has its own secret key plus the other side’s public key, with decryption proving origin. That unlocks product capabilities such as partner integrations, signed-and-encrypted webhooks, cross-tenant data exchange, and device-to-server messaging without inventing a custom protocol.AnonymousPublicKeyEncryption lets a deployment encrypt with only a public key and never hold the ability to decrypt. This is directly useful for roadmap decisions around compliance-sensitive ingestion, audit log shipping, telemetry pipelines, and “collect but do not read” data flows.needsReEncrypt() return true for all pre-v3 data, and preserves backward decryption permanently. This supports decisions about re-encryption sweeps, key rotation rollouts, and how much migration debt to schedule versus defer.prefix_secret_hex / prefix_public_hex values.spaze/phpstan-disallowed-calls (including non-timing-safe encoding rules) plus an AGENTS.md of invariants signals a maintainer willing to enforce cryptographic discipline. That is relevant to decisions about accepting AI-generated or contractor code touching encryption.Consider adoption when:
FormatMarkerMismatchException / UnknownFormatMarkerException, named creator class and method in errors, and key-slot validation at object construction.Look elsewhere or defer when:
InvalidMessage or InvalidNumberOfComponentsException; v3 throws new types and existing catch blocks will not catch them.needsReEncrypt() returning true for everything written before v3 means a re-encryption sweep is now on your roadmap, and rows created with encryptWithAd() must be re-encrypted with the correct additional data.paragonie/halite 5.1+ or cannot adopt that bump.To executives: This release turns a solid symmetric-encryption utility into a broader data-protection capability. We can now support two-party encrypted exchange and write-only data ingestion without building custom cryptography, which reduces engineering risk and shortens time-to-market for partner and compliance-sensitive features. The main cost is a coordinated upgrade: every deployment that reads or writes shared encrypted data must move to v3 before new data is written, and we should schedule a re-encryption sweep. That is a bounded, one-time migration with permanent backward decryption guarantees.
To engineering: v3.0.0 adds AuthenticatedPublicKeyEncryption and AnonymousPublicKeyEncryption, both configured with the same prefix_hex style as symmetric keys, with tagged prefix_secret_hex / prefix_public_hex values recommended so mis-pasted keys fail at construction. Stored values now carry a format marker and key id ($keyId$SymV1$..., SymAdV1, AuthV1, AuthAdV1, AnonV1), which are covered by decryption verification except in AnonymousPublicKeyEncryption. Mixed-up values throw FormatMarkerMismatchException or UnknownFormatMarkerException; audit existing catch blocks for Halite’s InvalidMessage / InvalidNumberOfComponentsException. needsReEncrypt() now returns true for all pre-v3 values, so the existing re-encryption sweep becomes the migration path; rows from encryptWithAd() must be re-encrypted with the row’s additional data. Bump paragonie/halite to 5.1+. Upgrade all deployments before writing marked values, since older versions cannot read them. Exception messages now shorten and sanitize key ids/markers to keep key material out of logs, and PHPStan with spaze/phpstan-disallowed-calls plus AGENTS.md invariants now gate contributions.
To security/compliance: The package now enforces correct key placement at construction, binds key id and format marker into authenticated decryption, and reduces leakage through logs. Backward compatibility is explicit: everything written by prior versions still decrypts, and the “key id not protected against tampering” caveat is limited to old-format values once migration completes. The remaining operational obligation is to complete the re-encryption sweep and to sequence the multi-deployment upgrade correctly.
How can I help you explore Laravel packages today?