2017 © Pedro Peláez
 

library encryptable

Allows you to store Eloquent properties encrypted in your database, and automatically decrypt when accessed.

image

sagalbot/encryptable

Allows you to store Eloquent properties encrypted in your database, and automatically decrypt when accessed.

  • Wednesday, April 19, 2017
  • by sagalbot
  • Repository
  • 2 Watchers
  • 9 Stars
  • 2,578 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 2 Versions
  • 13 % Grown

The README.md

Encryptable Eloquent Model Properties Build Status

A Laravel 5 package that allows you to store Eloquent model properties encrypted in your database, and automatically decrypts them when you need to access them., (*1)

example, (*2)

Install

composer require sagalbot/encryptable

Usage

This package is really just a simple trait and property that you can add to your Eloquent models. Usage is simple:, (*3)

  1. Before using Laravel's encrypter, you must set a key option in your config/app.php configuration file., (*4)

    artisan key:generate
    

    note: If you already have APP_KEY set in your .env, you should skip this step., (*5)

  2. Use the Sagalbot\Encryptable\Encryptable trait:, (*6)

    use \Sagalbot\Encryptable\Encryptable;
    
  3. Set the $encryptable array on your Model., (*7)

    protected $encryptable = ['my_encrypted_property'];
    
  4. That's it! Here's a complete example:, (*8)

    <?php
    
    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    use Sagalbot\Encryptable\Encryptable;
    
    class MyEncryptedModel extends Model
    {
    
        use Encryptable;
    
        /**
         * The attributes that should be encrypted when stored.
         *
         * @var array
         */
        protected $encryptable = [ 'my_encrypted_property', 'another_secret' ];
    }
    

Encryption Options

By default, the package uses the global encrypt() and decrypt() Laravel functions, which are just aliases to resolve the Illuminate\Encryption\Encrypter::class out of the container. Laravel's encrypter uses OpenSSL to provide AES-256 and AES-128 encryption, which you can read more about at the Laravel Docs., (*9)

If you need to adjust how a specific model encrypts and decrypts its properties, you can override the decryptAttribute and encryptAttribute methods on your model:, (*10)

/**
 * @param $value
 */
protected function encryptAttribute($value)
{
    //  encrypt the value
}


/**
 * @param $value
 */
protected function decryptAttribute($value)
{
    //  decrypt the value
}

Keep It Secret, Keep It Safe

Keep it Secret, Keep it Safe, (*11)

Don't lose your encryption key - you can't decrypt your stored data without it., (*12)

The Versions

19/04 2017

dev-master

9999999-dev

Allows you to store Eloquent properties encrypted in your database, and automatically decrypt when accessed.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

by Jeff Sagal

laravel eloquent encryption laravel 5

19/04 2017

v1.0.0

1.0.0.0

Allows you to store Eloquent properties encrypted in your database, and automatically decrypt when accessed.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

by Jeff Sagal

laravel eloquent encryption laravel 5