2017 © Pedro Peláez
 

library laracrypt

Add database encryption to laravel

image

garethnic/laracrypt

Add database encryption to laravel

  • Wednesday, March 16, 2016
  • by garethnic
  • Repository
  • 1 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

LaraCrypt

Latest Version on Packagist ![Software License][ico-license] Total Downloads, (*1)

A Laravel package to handle database encryption. In the current state of this project, only symmetric encryption is possible., (*2)

Install

Make sure you have libsodium installed., (*3)

Via Composer, (*4)

Add the following to your composer.json file:, (*5)

"garethnic/laracrypt": "dev-master"

Add the garethnic\ServiceProvider to your config/app.php providers array:, (*6)

``` php garethnic\laracrypt\LaraCryptServiceProvider::class,, (*7)


Then do: ``` bash $ php artisan vendor:publish

To copy the config file over. In this file you can specify where to store and load your key from., (*8)

``` php 'path' => storage_path('keys/encryption.key'), (*9)


**For your database schema make sure the encrypted columns are of type `BLOB`.** ## Usage You will first need to create your key: ``` bash $ 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., (*10)

In the future more options will be added to make key storage more flexible., (*11)

There are multiple ways to go about encrypting/decrypting:, (*12)

AppServiceProvider, (*13)

``` php // Encrypting all attributes Post::saving(function ($post) { foreach($post['attributes'] as $key => $value) { $post->$key = LaraCrypt::encrypt($value); } });, (*14)

// Encrypting all attributes Post::saving(function ($post) { $post->body = LaraCrypt::encrypt($post->body); });, (*15)


Or in your `Model` you could do: ``` php public function setBodyAttribute($value) { $this->attributes['title'] = LaraCrypt::encrypt($value); }

Decrypting:, (*16)

It's as simple as LaraCrypt::decrypt($text)., (*17)

In your Model:, (*18)

``` php public function getBodyAttribute($value) { return LaraCrypt::decrypt($value); }, (*19)


## TODO * Add configuration options * Add support for asymmetric encryption * Clean up code * Write tests ## Change log Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. ## Testing ``` bash $ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*20)

License

The MIT License (MIT). Please see License File for more information., (*21)

The Versions

16/03 2016

dev-master

9999999-dev https://github.com/garethnic/laracrypt

Add database encryption to laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel encryption garethnic laracrypt