PHPackages                             adayth/cakephp-cipher-behavior - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. adayth/cakephp-cipher-behavior

ActiveCakephp-plugin[Security](/categories/security)

adayth/cakephp-cipher-behavior
==============================

Secure your DB data with CakePHP ORM and this behavior

1.0.0(10y ago)96.2k4[2 issues](https://github.com/adayth/cakephp-cipher-behavior/issues)[1 PRs](https://github.com/adayth/cakephp-cipher-behavior/pulls)MITPHPPHP &gt;=5.4.16

Since Jun 24Pushed 5y ago1 watchersCompare

[ Source](https://github.com/adayth/cakephp-cipher-behavior)[ Packagist](https://packagist.org/packages/adayth/cakephp-cipher-behavior)[ Docs](https://github.com/adayth/cakephp-cipher-behavior)[ RSS](/packages/adayth-cakephp-cipher-behavior/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

CipherBehavior plugin for CakePHP
=================================

[](#cipherbehavior-plugin-for-cakephp)

Cipher your entities data magically with CakePHP Security class and this behavior.

Installation
------------

[](#installation)

First install this plugin into your CakePHP application using [composer](http://getcomposer.org).

The easy way to install composer packages is:

```
composer require adayth/cakephp-cipher-behavior

```

After that you should load the plugin in your app editing `config/bootstrap.php`:

```
Plugin::load('CipherBehavior');
```

Usage
-----

[](#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.

Table schema example for storing encrypted credit cards:

```
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:

```
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
----------------------

[](#behavior-configuration)

Configuration allows to specify what fields are managed by the behavior and configure encryption key/salt.

- **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](http://book.cakephp.org/3.0/en/orm/database-basics.html#data-types)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:

```
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](https://api.wordpress.org/secret-key/1.1/salt/), [Random Key Generator](http://randomkeygen.com/) or allow your cat/dog/insert your pet here to play with your keyboard a minute...

Implementation notes
--------------------

[](#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.

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

Support
-------

[](#support)

For bugs and feature requests, please use the [issues](https://github.com/adayth/cakephp-cipher-behavior/issues) section of this repository.

Contributing
------------

[](#contributing)

Contributions are welcome. You sohuld follow this guide:

- Pull requests must be send to the `dev` branch.
- Follow [CakePHP coding standard](http://book.cakephp.org/3.0/en/contributing/cakephp-coding-conventions.html).
- Please, add [Tests](http://book.cakephp.org/3.0/en/development/testing.html) to new features.

License
-------

[](#license)

Copyright 2015, Aday Talavera &lt;aday.talavera at gmail.com&gt;

Licensed under The MIT License.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3982d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/042ee61ee9c3c39d5f3555468dde0fc73739497f59bed478fbc85f26fd640349?d=identicon)[adayth](/maintainers/adayth)

---

Top Contributors

[![adayth](https://avatars.githubusercontent.com/u/1223929?v=4)](https://github.com/adayth "adayth (18 commits)")[![lorenzo](https://avatars.githubusercontent.com/u/37621?v=4)](https://github.com/lorenzo "lorenzo (2 commits)")

---

Tags

plugincakephpencryptdecryptcipherbehaviorscryptcypherPCI Compliance

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/adayth-cakephp-cipher-behavior/health.svg)

```
[![Health](https://phpackages.com/badges/adayth-cakephp-cipher-behavior/health.svg)](https://phpackages.com/packages/adayth-cakephp-cipher-behavior)
```

###  Alternatives

[dereuromark/cakephp-tools

A CakePHP plugin containing lots of useful and reusable tools

338920.1k32](/packages/dereuromark-cakephp-tools)[xxtea/xxtea

XXTEA is a fast and secure encryption algorithm. This is a XXTEA library for PHP.

11341.7k](/packages/xxtea-xxtea)[miladrahimi/phpcrypt

Encryption, decryption, and hashing tools for PHP projects

3171.5k2](/packages/miladrahimi-phpcrypt)[poly-crypto/poly-crypto

High-level cryptographic functions that are interoperable between NodeJS and PHP 7.1+

127.8k1](/packages/poly-crypto-poly-crypto)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
