keboola/object-encryptor
Keboola Object Encryptor is a PHP library for encrypting and decrypting arbitrary PHP data such as arrays and objects. It wraps OpenSSL-backed encryption with configurable key handling, helping Laravel and standalone PHP applications protect sensitive data at rest with minimal integration effort.
keboola/object-encryptor is not Laravel-specific — it's a standalone PHP library — so treat it as a service you register in the container rather than a facade. Start here:
composer require keboola/object-encryptor (2.14.2 or later — see Gotchas).config/object-encryptor.php with stack_id, kms_region, key_id (or Key Vault credentials) sourced from env. Never hardcode the ARN/vault URL.AppServiceProvider via ObjectEncryptorFactory, passing an Aws\Kms\KmsClient (or the Key Vault client) and setStackId(). Resolve it through the container everywhere; the factory setup is expensive relative to encrypt/decrypt calls.text column. Encrypt on save in a model mutator, decrypt in an accessor or a dedicated CredentialsRepository — not both, or you'll double-encrypt.If all you need is encrypting a plain string and you control both ends inside the same Laravel app, Crypt::encryptString() is simpler. Reach for this package when you need Keboola-compatible wrappers (component/configuration/project scoping) or KMS/Key Vault-backed keys.
encryptGeneric() for anything not tied to a tenant; encryptForComponent($data, $componentId) when the ciphertext must be readable only by one component; encryptForConfiguration(...) and encryptForProject(...) when scope matters. Pick the narrowest scope up front — the ciphertext embeds the scope, so widening later means re-encrypting.toArray() ciphertext or plaintext into logs and API responses.key_version column alongside the ciphertext; on decrypt, if the version is stale, re-encrypt and persist. Decryption failures should fall back to a re-auth flow, not a 500.ObjectEncryptor test helper that round-trips fixtures.unserialize() now runs with ['allowed_classes' => false]. The wire format is unchanged, so scalars, arrays, and strings round-trip exactly as before and no re-encryption is needed. But if you ever encrypted actual objects, decrypt*() will now hand back __PHP_Incomplete_Class instead of your type. Audit for object payloads before upgrading and convert to arrays.TEXT/LONGTEXT, not VARCHAR(255), and don't index ciphertext.Crypt. Different key derivation and envelope. Never mix the two on the same column; pick one per field and document it.AppServiceProvider keyed off the environment, or onboarding stalls on day one.ObjectEncryptor itself only orchestrates wrappers.How can I help you explore Laravel packages today?