Download the PHP package spatie/laravel-ciphersweet without Composer
On this page you can find all versions of the php package spatie/laravel-ciphersweet. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download spatie/laravel-ciphersweet
More information about spatie/laravel-ciphersweet
Files in spatie/laravel-ciphersweet
Package laravel-ciphersweet
Short Description Use ciphersweet in your Laravel project
License MIT
Homepage https://github.com/spatie/laravel-ciphersweet
Informations about the package laravel-ciphersweet
Use CipherSweet in your Laravel project
In your project, you might store sensitive personal data in your database. Should an unauthorised person get access to your DB, all sensitive can be read which is obviously not good.
To solve this problem, you can encrypt the personal data. This way, unauthorized persons cannot read it, but your application can still decrypt it when you need to display or work with the data.
CipherSweet is a backend library developed by Paragon Initiative Enterprises for implementing searchable field-level encryption. It can encrypt and decrypt values in a very secure way. It is also able to create blind indexes. These indexes can be used to perform searches on encrypted data. The indexes themselves are unreadable by humans.
Our package is a wrapper over CipherSweet, which allows you to easily use it with Laravel's Eloquent models.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
You must publish and run the migrations with:
Optionally, you can publish the config file with:
This is the contents of the config file:
Usage
Few steps are involved to store encrypted values. Let's go through them.
1. Preparing your model and choosing the attributes that should be encrypted
Add the CipherSweetEncrypted
interface and UsesCipherSweet
trait to the model that you want to add encrypted fields to.
You'll need to implement the configureCipherSweet
method to configure CipherSweet.
* ->addField('column_name')
* ->addBooleanField('column_name')
* ->addIntegerField('column_name')
* ->addTextField('column_name')
*
* ->addOptionalTextField('column_name')
* ->addOptionalBooleanField('column_name')
* ->addOptionalFloatField('column_name')
* ->addOptionalIntegerField('column_name')
*
* ->addJsonField('column_name', $fieldMap)
*
* ->addBlindIndex('column_name', new BlindIndex('column_name_index'))
*
The example above will encrypt the email
field on the User
model. It also adds a blind index in the blind_indexes
table which allows you to search on it.
Check out the CipherSweet PHP docs for more information on what is possible.
2. Generating the encrypting key
An encryption key is used to encrypt your values. You can generate a new CipherSweet encrypting key using this command:
3. Updating your .env file
After the key has been generated, you should add the generated CipherSweet key to your .env file.
The key will be used by your application to manage encrypted values.
4. Encrypting model attributes
With this in place, you can run this command to encrypt all values:
The command will update all the encrypted fields and blind indexes of the model.
If you have a lot of rows, this process can take a long time. The command is restartable: it can be re-run without needing to re-encrypt already rotated keys.
Searching on blind indexes
Even though values are encrypted, you can still search them using a blind index. The blind indexes will have been built up when you ran the command to encrypt the model values.
This package provides a whereBlind
and orWhereBlind
scope to search on blind indexes.
The first parameter is the column, the second the index name you set up when calling ->addBlindIndex
, the third is the raw value, the package will automatically apply any transformations and hash the value to search on the blind index.
Rotating keys
Should you suspect that somebody got a hold of your encrypting key, you can re-encrypt the values. Simply generate another encrypting key, and run the php artisan ciphersweet:encrypt
command again.
This will update all the encrypted fields and blind indexes of the model. Once this is done, you can update your environment or config file to use the new key.
Implementing a custom backend
You can implement a custom backend by setting the ciphersweet.backend
config value to custom
.
The ciphersweet.backend.custom
config value must then be set to an invokeable factory class that returns an implementation of ParagonIE\CipherSweet\Contract\BackendInterface
Implementing a custom key provider
You can implement a custom key provider by setting the ciphersweet.provider
config value to custom
.
The ciphersweet.providers.custom
config value must then be set to an invokeable factory class that returns an implementation of ParagonIE\CipherSweet\Contract\KeyProviderInterface
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Rias Van der Veken
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-ciphersweet with dependencies
illuminate/contracts Version ^9.19|^10.0|^11.0
paragonie/ciphersweet Version ^4.0.1
spatie/laravel-package-tools Version ^1.12.0