Package Data | |
---|---|
Maintainer Username: | garethnic |
Maintainer Contact: | gareth.nic@gmail.com (Gareth Nicholson) |
Package Create Date: | 2016-03-15 |
Package Last Update: | 2016-03-16 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-20 03:01:55 |
Package Statistics | |
---|---|
Total Downloads: | 0 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 1 |
A Laravel package to handle database encryption. In the current state of this project, only symmetric encryption is possible.
Make sure you have libsodium installed.
Via Composer
Add the following to your composer.json
file:
"garethnic/laracrypt": "dev-master"
Add the garethnic\ServiceProvider to your config/app.php providers array:
garethnic\laracrypt\LaraCryptServiceProvider::class,
Then do:
$ php artisan vendor:publish
To copy the config file over. In this file you can specify where to store and load your key from.
'path' => storage_path('keys/encryption.key')
For your database schema make sure the encrypted columns are of type BLOB
.
You will first need to create your key:
$ php artisan laracrypt:key
This will generate a key and save it in storage/keys
. You could also generate the key programmatically via the static generateKey
method.
In the future more options will be added to make key storage more flexible.
There are multiple ways to go about encrypting/decrypting:
AppServiceProvider
// Encrypting all attributes
Post::saving(function ($post) {
foreach($post['attributes'] as $key => $value) {
$post->$key = LaraCrypt::encrypt($value);
}
});
// Encrypting all attributes
Post::saving(function ($post) {
$post->body = LaraCrypt::encrypt($post->body);
});
Or in your Model
you could do:
public function setBodyAttribute($value)
{
$this->attributes['title'] = LaraCrypt::encrypt($value);
}
Decrypting:
It's as simple as LaraCrypt::decrypt($text)
.
In your Model
:
public function getBodyAttribute($value)
{
return LaraCrypt::decrypt($value);
}
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
The MIT License (MIT). Please see License File for more information.