2017 © Pedro Peláez
 

cakephp-plugin cakephp-cipher-behavior

Secure your DB data with CakePHP ORM and this behavior

image

adayth/cakephp-cipher-behavior

Secure your DB data with CakePHP ORM and this behavior

  • Wednesday, January 20, 2016
  • by adayth
  • Repository
  • 1 Watchers
  • 9 Stars
  • 501 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 3 Versions
  • 4 % Grown

The README.md

CipherBehavior plugin for CakePHP

Cipher your entities data magically with CakePHP Security class and this behavior., (*1)

Installation

First install this plugin into your CakePHP application using composer., (*2)

The easy way to install composer packages is:, (*3)

composer require adayth/cakephp-cipher-behavior

After that you should load the plugin in your app editing config/bootstrap.php:, (*4)

Plugin::load('CipherBehavior');

Usage

You can add this behavior to a table to encrypt/decrypt your entities data while saving/retrieving them from DB. To use it you should define binary columns in your table schema to store encrypted data., (*5)

Table schema example for storing encrypted credit cards:, (*6)

CREATE TABLE IF NOT EXISTS `credit_cards` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `type` blob NOT NULL,
  `number` blob NOT NULL,
  `expire_date` blob NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Following the example, to use the behavior with this table:, (*7)

class CreditCardsTable extends Table
{
    public function initialize(array $config)
    {
        parent::initialize($config);

        // Add Cipher behavior
        $this->addBehavior('CipherBehavior.Cipher', [
            'fields' => [
                'type' => 'string',
                'number' => 'string',
                'expire_date' => 'date',
            ]
        ]);
    }
}

Behavior configuration

Configuration allows to specify what fields are managed by the behavior and configure encryption key/salt., (*8)

  • fields (required): array of fields to be managed by the behavior. Keys are column names and values are column types registered in Cake\Database\Type. See CakePHP Book - DataTypes to view core CakePHP types.
  • key (required/optional): you can specify a key to be used by Security class to encrypt/decrypt data as part of behavior config.
  • salt (required/optional): you can specify a salt to be used by Security class to encrypt/decrypt data as part of behavior config.

key and salt can also be set globally using two configuration keys: App.Encrypt.key and App.Encrypt.salt. Example:, (*9)

Configure::write('App.Encrypt.key', 'your long not legible key');
Configure::write('App.Encrypt.salt', 'your long not legible salt');

To get a good pair of key and salt, you could use Wordpress key/salt generator, Random Key Generator or allow your cat/dog/insert your pet here to play with your keyboard a minute..., (*10)

Implementation notes

The ciphering is done with beforeSave and beforeFind events, using CakePHP Security class encrypt / decrypt methods and Cake\Database\Type to convert data from and to DB to the right types. Type columns use is needed because all data is stored and ciphered in DB in binary format. So before/after encrypt/decrypt casting types is needed., (*11)

Important: Current tests only covers string, integer and date column types., (*12)

Support

For bugs and feature requests, please use the issues section of this repository., (*13)

Contributing

Contributions are welcome. You sohuld follow this guide:, (*14)

License

Copyright 2015, Aday Talavera <aday.talavera at gmail.com>, (*15)

Licensed under The MIT License., (*16)

The Versions

20/01 2016

dev-master

9999999-dev https://github.com/adayth/cakephp-cipher-behavior

Secure your DB data with CakePHP ORM and this behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

orm plugin cakephp encrypt decrypt behaviors crypt cipher cypher pci compliance

14/07 2015

dev-dev

dev-dev https://github.com/adayth/cakephp-cipher-behavior

Secure your DB data with CakePHP and this behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp encrypt decrypt behaviors crypt cipher cypher pci compliance

24/06 2015

1.0.0

1.0.0.0 https://github.com/adayth/cakephp-cipher-behavior

Secure your DB data with CakePHP and this behavior

  Sources   Download

MIT

The Requires

 

The Development Requires

plugin cakephp encrypt decrypt behaviors crypt cipher cypher pci compliance