Encryption/Decryption of Form Fields in CakePHP 3
I want to have some form-fields encrypted when they are added/edited and decrypted when they are looked up by cake. Here is the code that works for me in v2.7.2: core.php Configure::write('Security.key','secretkey'); app/model/patient.php. public $encryptedFields = array('patient_surname', 'patient_first_name'); public function beforeSave($options = array()) { foreach($this->encryptedFields as $fieldName){ if(!empty($this->data[$this->alias][$fieldName])){ $this->data[$this->alias][$fieldName] = Security::encrypt( $this->data[$this->alias][$fieldName], Configure::read('Security.key') ); } }