This package contains several Laravel utilities to work with encrypted data.
Via Composer
$ composer require swisnl/laravel-encrypted-data
N.B. Using Laravel 6-8? Please use version 1.x of this package.
Warning
Laravel supports encrypted casts since version 8.12, so new projects should use that instead of the models provided by this package.
We aim to provide a migration path to encrypted casts. See issue #1 for more information.
Extend \Swis\Laravel\Encrypted\EncryptedModel
in your model and define the encrypted fields. Make sure your database columns are long enough, so your data isn't truncated!
protected $encrypted = [
'secret',
];
You can now simply use the model properties as usual and everything will be encrypted/decrypted under the hood!
Configure the storage driver in config/filesystems.php
.
'disks' => [
'local' => [
'driver' => 'local-encrypted',
'root' => storage_path('app'),
],
],
You can now simply use the storage methods as usual and everything will be encrypted/decrypted under the hood!
Due to the encryption, some issues/limitations apply:
- Encrypted data is — depending on what you encrypt — roughly 30-40% bigger.
- You can't query or order columns that are encrypted in your SQL-statements, but you can query or sort the results using collection methods;
- All data is being serialized before it is encrypted — and unserialized after it is decrypted — so everything is stored exactly as how Laravel would insert it into the database. You can use Eloquent Mutators as you normally would.
- You can't use the public disk as that will download the raw encrypted files, so using
Storage::url()
andStorage::temporaryUrl()
does not make sense; - You can use streams with this disk, but internally we will always convert those to strings because the entire file contents need to be encrypted/decrypted at once.
Please see CHANGELOG for more information on what has changed recently.
$ composer test
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
SWIS is a web agency from Leiden, the Netherlands. We love working with open source software.