PHPackages                             joacir/cake-aes - 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. joacir/cake-aes

ActiveCakephp-plugin

joacir/cake-aes
===============

Encrypt and decrypt fields using AES-256 plugin for CakePHP

2.1(7mo ago)2122MITPHPPHP &gt;=7.4

Since Jan 14Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/joacir/CakeAes)[ Packagist](https://packagist.org/packages/joacir/cake-aes)[ Docs](https://joacir.dev)[ RSS](/packages/joacir-cake-aes/feed)WikiDiscussions main Synced 6d ago

READMEChangelog (6)Dependencies (4)Versions (16)Used By (0)

CakeAes
=======

[](#cakeaes)

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)

Install it as require dependency:

```
composer require joacir/CakeAes

```

Setup
-----

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

[](#usage)

### To encrypt fields

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

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

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

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

```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance62

Regular maintenance activity

Popularity10

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% 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

Every ~192 days

Recently: every ~288 days

Total

8

Last Release

235d ago

Major Versions

1.4 → 2.02024-03-22

PHP version history (2 changes)1.0PHP &gt;=7.2

2.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/f1a6726510ce93609b7b823e0cff4434352b8eb76039f6505540b8e9a2c05a83?d=identicon)[joacir](/maintainers/joacir)

---

Top Contributors

[![joacir](https://avatars.githubusercontent.com/u/342486?v=4)](https://github.com/joacir "joacir (36 commits)")[![lupainformatica](https://avatars.githubusercontent.com/u/67587830?v=4)](https://github.com/lupainformatica "lupainformatica (7 commits)")[![gildonei](https://avatars.githubusercontent.com/u/1370979?v=4)](https://github.com/gildonei "gildonei (3 commits)")[![dereuromark](https://avatars.githubusercontent.com/u/39854?v=4)](https://github.com/dereuromark "dereuromark (1 commits)")[![junior-lupainformatica](https://avatars.githubusercontent.com/u/67591912?v=4)](https://github.com/junior-lupainformatica "junior-lupainformatica (1 commits)")

---

Tags

phpencryptlgpdAES-256

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/joacir-cake-aes/health.svg)

```
[![Health](https://phpackages.com/badges/joacir-cake-aes/health.svg)](https://phpackages.com/packages/joacir-cake-aes)
```

###  Alternatives

[soarecostin/file-vault

192195.0k](/packages/soarecostin-file-vault)[poly-crypto/poly-crypto

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

127.8k1](/packages/poly-crypto-poly-crypto)[brainstud/file-vault

1231.6k](/packages/brainstud-file-vault)[hemiframe/php-aes

PHP class for encrypt and decrypt data with AES algorithm

1030.3k](/packages/hemiframe-php-aes)

PHPackages © 2026

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