joacir/cake-aes
Composer 安装命令:
composer require joacir/cake-aes
包简介
Encrypt and decrypt fields using AES-256 plugin for CakePHP
README 文档
README
CakePHP plugin to encrypt/decrypt table fields using AES-256 algorithm on MySQL/MariaDB databases. This branch is for use with CakePHP 5.0+. Use branch "main-cake4" to use with CakePHP 4.0+
Install
Install it as require dependency:
composer require joacir/CakeAes
Setup
Enable the plugin in your Application.php or call
bin/cake plugin load CakeAes
Configure a new security hash in app_local.php:
'Security' => [
'key' => '34601affc03a12d4b963b6123ab3afcb',
],
- This will be the key used by the plugin for encryption.
- NEVER use the same key for different apps.
- Once generated, NEVER change the key.
- The key must contain at least 32 digits in hexadecimal.
Change the type field of the fields you want to encrypt on your tables to a binary type:
char(20) -> blob
vachar(200) -> varbinary(200)
text -> blob
- Only string types works. Use only VarBinary or Blob types.
Load the behavior on your table initialize() method:
$this->addBehavior('CakeAes.Encrypt', [
'fields' => ['name', 'card', 'phone']
]);
Usage
To encrypt fields
Nothing is necessary, the EncryptBehavior do the encryption automatically when you set the fields in settings.
To decrypt fields, conditions, order and contain
The find() ou get() works without changes, in complex queries you can use decryptField() or decryptString().
$new = $this->Temps->get($temp->id, ['fields' => [
'id',
'name' => $this->Temps->decryptField('Temps.name')
]]);
$temp = $this->Temps->find()
->select(['name' => $this->Temps->decryptField('Temps.name')])
->where(['id' => 2])
->first();
You can use decryptEq() in conditions:
$temp = $this->Temps->find()
->select(['name' => $this->Temps->decryptField('Temps.name')])
->where([$this->Temps->decryptEq('Temps.name', $name)])
->first();
$temp = $this->Temps->find()
->select([
'id',
'name' => $this->Temps->decryptField('Temps.name')
])
->where([$this->Temps->decryptLike('Temps.name', '%Sa%')])
->first();
In updateAll() you can use encrypt() to encrypt:
$name = $this->Temps->encrypt("José");
$fields = ['name' => $name];
$conditions = [
$this->Temps->decryptEq('Temps.name', 'Maria')
];
$this->Temps->updateAll($fields, $conditions);
To encrypt/decrypt a file
$imageFile = dirname(__FILE__) . DS . 'imagem.jpg';
$Temps->encryptFile($imageFile);
$imageFile = dirname(__FILE__) . DS . 'imagem_crypted.jpg';
$Temps->decryptFile($imageFile);
To decrypt a file in a controller
Load de Encrypt Component:
public function initialize(): void
{
$this->loadComponent('CakeAes.Encrypt');
}
To decrypt and render the content:
$imageFile = dirname(__FILE__) . DS . 'imagem_encrypted.jpg';
return $this->Encrypt->decryptRender($imageFile);
To decrypt and download a file:
$imageFile = dirname(__FILE__) . DS . 'imagem_encrypted.jpg';
return $this->Encrypt->decryptDownload($imageFile);
joacir/cake-aes 适用场景与选型建议
joacir/cake-aes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 01 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「encrypt」 「AES-256」 「lgpd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 joacir/cake-aes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 joacir/cake-aes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 joacir/cake-aes 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Encrypted symfony entity's by verified and standardized libraries
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
High-level cryptographic functions that are interoperable between NodeJS and PHP 7.1+
♺ Laravel Nova Hashids card. Convert your ids.
A library for reading KeePass 2.x databases
A PHP library for RSA encryption and decryption using the OpenSSL extension
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-14