paragonie/sodium_compat
Pure PHP polyfill for libsodium (Sodium crypto), transparently using the PHP extension when installed. Supports PHP 5.2.4+ and 32-bit integers in v1.x, with v2.x targeting PHP 8.1+.
ext-sodium being present on every host in your fleet, including customer-managed, on-prem, or shared-hosting deployments.polyfill_is_fast() helper is the key hook: it lets you route crypto-heavy work to a queue or cron when the fast path isn't available, which is a user-visible latency decision (e.g., synchronous file encryption on upload vs. asynchronous background processing).crypto_box_seal for PII shared to a recipient's public key, crypto_secretstream for large-file envelope encryption, and Ed25519→Curve25519 conversion for mixing signing and encryption keys. These are roadmap items that become cheap if the primitives are already a dependency, and expensive (or outsourced to a KMS) if not.composer why triage. Because this arrives transitively via other packages, it shows up in SBOM/vulnerability reviews and can pin your PHP floor. Owning that decision deliberately (rather than discovering it) avoids surprise upgrade blocks.Adopt when:
"paragonie/sodium_compat": ">= 1" constraint, which is exactly the posture a reusable Laravel package should take.ext-sodium cannot be guaranteed.openssl_* doesn't give you cleanly: sealed boxes, detached signatures, crypto_kx session keys, secretstream for chunked file encryption, XChaCha20 variants, AEGIS AEAD, or Ristretto255 for advanced protocols.sodium_* → ParagonIE_Sodium_Compat:: translation to reduce blast radius.Look elsewhere when:
ext-sodium. On Laravel 9+/PHP 8.x containerized deployments, the extension is almost always available and dramatically faster; the polyfill is then dead weight and an extra supply-chain surface. Mandate the extension in your base image instead.Crypt facade and the encrypted cast already handle this; adding a crypto dependency for that need is unjustified.Hash (Argon2id/bcrypt). This is not a password-hashing tool.Practical verification before adopting: run composer why paragonie/sodium_compat (note: the "0 dependents" figure in the package metadata looks understated and should not be treated as an adoption signal — the README cites Joomla! and Magento, and the real installed base is much wider), confirm which major version your constraint resolves to, and check whether sodium_crypto_* functions are already available in your production image.
For executives: This is a small, ISC-licensed, well-maintained compatibility layer for the standard modern PHP encryption library. It costs us nothing, carries no vendor lock-in, and removes a class of "our app won't install on that customer's server" escalations. It does not replace our key management story, and it has not been formally audited — so it's low-cost insurance for portability, not a compliance shortcut. The alternative to adopting it is either (a) supporting only hosts where we control the PHP build, or (b) hand-rolling crypto, which is strictly worse.
For engineering: Drop-in polyfill — you write sodium_* calls (or ParagonIE_Sodium_Compat:: if you need PHP 5.2-era support) and it transparently uses ext-sodium when present, falling back to pure PHP when it isn't. Constraints: use >= 1 if we're publishing a package, pin explicitly if we're an application; v1.x if we must keep 32-bit or pre-7.2 support, v2.x (PHP 8.1+, 64-bit, faster, smaller) otherwise. Releases are GPG-signed and available as a phar for non-Composer installs. Use polyfill_is_fast() to decide sync vs. queued execution for anything crypto-heavy, and never set $fastMult = true without verifying the target CPU — the README spells out that trade-off. Don't use it for password hashing (use Hash) or for the standard encrypted cast (Crypt already covers it); reserve it for sealed boxes, detached signatures, secretstream file encryption, and cross-platform interop.
How can I help you explore Laravel packages today?