A CakePHP behavior to automatically encrypt and decrypt data passed through the ORM.
varbinary(1024)Attach it to your model's Table class in its initialize() method like so:
$this->addBehavior('Tools.Encryption', [
'fields' => ['secret_field'],
'key' => \Cake\Core\Configure::read('Security.encryption')
]);
After attaching the behavior, a call like
$user = $this->Users->newEmptyEntity();
$user = $this->Users->patchEntity($user, [
'username' => 'cake',
'password' => 'a random generated string hopefully'
'secret_field' => 'my super mysterious secret'
]);
$this->Users->saveOrFail($user);
will result in the secret_field to be automatically encrypted.
Same goes for when you are fetching the entry from the ORM via
$user = $this->Users->get($id);
// or
$users = $this->Users->find()->all();
will automatically decrypt the binary data.
Security.salt value.