adayth/cakephp-cipher-behavior
Composer 安装命令:
composer require adayth/cakephp-cipher-behavior
包简介
Secure your DB data with CakePHP ORM and this behavior
README 文档
README
Cipher your entities data magically with CakePHP Security class and this behavior.
Installation
First install this plugin into your CakePHP application using composer.
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
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
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 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, Random Key Generator or allow your cat/dog/insert your pet here to play with your keyboard a minute...
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
For bugs and feature requests, please use the issues section of this repository.
Contributing
Contributions are welcome. You sohuld follow this guide:
- Pull requests must be send to the
devbranch. - Follow CakePHP coding standard.
- Please, add Tests to new features.
License
Copyright 2015, Aday Talavera <aday.talavera at gmail.com>
Licensed under The MIT License.
adayth/cakephp-cipher-behavior 适用场景与选型建议
adayth/cakephp-cipher-behavior 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.26k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2015 年 06 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「plugin」 「behaviors」 「cakephp」 「crypt」 「encrypt」 「decrypt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 adayth/cakephp-cipher-behavior 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adayth/cakephp-cipher-behavior 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adayth/cakephp-cipher-behavior 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Doctrine2 behavior traits - slowhop fork
Doctrine2 behavior traits
Email Toolkit Plugin for CakePHP
Rhino, a CMS and Application-Framework plugin for CakePHP
A CakePHP plugin for sending mail via SparkPost's REST API
统计信息
- 总下载量: 6.26k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-24