Download the PHP package wazza/laravel-db-encryption without Composer
On this page you can find all versions of the php package wazza/laravel-db-encryption. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wazza/laravel-db-encryption
More information about wazza/laravel-db-encryption
Files in wazza/laravel-db-encryption
Package laravel-db-encryption
Short Description A Laravel package that helps encrypt & decrypt certain defined table columns ensuring the data is secure in the database but can be accessed by the models.
License MIT
Homepage https://www.wazzac.dev
Informations about the package laravel-db-encryption
Laravel DB Encryptor
A Laravel package for secure, transparent encryption and decryption of sensitive model attributes, storing them in a dedicated table while keeping your main tables clean and fast.
Features
- Seamless encryption/decryption of model attributes via a simple trait
- Encrypted data is stored in a separate
encrypted_attributes
table - Only non-table attributes can be encrypted (enforced at runtime)
- Automatic loading and saving of encrypted attributes using Eloquent events
- Search/filter on encrypted properties using SHA-256 hash
- No sensitive values are ever logged
- Easy integration: just add the trait and define
$encryptedProperties
in your model - Compatible with Laravel 9+
Requirements
- PHP 8.1+
- Laravel 9 or higher
- OpenSSL PHP extension
How It Works
- Add the
HasEncryptedAttributes
trait to your Eloquent model. - Define a public array property
$encryptedProperties
listing the attributes you want encrypted (these must NOT exist as columns in the model's table). - When you load a model, encrypted attributes are automatically decrypted and available as normal properties.
- When you save a model, encrypted attributes are removed from the main table and securely stored in the
encrypted_attributes
table. - You can filter/search on encrypted properties using the provided query scope.
Example Model:
Usage
-
Use your model as normal:
- If you try to add an attribute to
$encryptedProperties
that already exists as a column, an exception will be thrown.
Filtering/Search on Encrypted Properties
You can filter or search for models by encrypted property value using the built-in query scope:
This uses the SHA-256 hash of the value and joins the encrypted_attributes
table for efficient searching, without ever exposing the decrypted value in the query or logs.
Installation Steps
-
Require the package in your Laravel project:
-
Publish the config and migration files (if needed):
-
Run the migration to create the
encrypted_attributes
table: - Add the trait and
$encryptedProperties
to your models as shown above.
Monitoring & Logs
- All encryption/decryption operations are logged (without sensitive values).
- To monitor package logs:
Testing
-
Run the test suite using Pest:
- Ensure your models and encrypted attributes behave as expected.
For more details, see the source code and comments. Contributions and issues welcome!