public function beforeSave(Event $event, EntityInterface $entity)
    {
        $driver = $this->_table->connection()->driver();

        foreach ($this->config('fields') as $field => $type) {
            if (!$entity->has($field)) {
                continue;
            }

            $raw = $entity->get($field);
            $plain = Type::build($type)->toDatabase($raw, $driver);
            $entity->set($field, $this->encrypt($plain));
        }
    }
public function beforeSave(Event $event, EntityInterface $entity)
    {
        $driver = $this->_table->connection()->driver();

        foreach ($this->config('fields') as $field => $type) {
            if (!$entity->has($field)) {
                continue;
            }

            $raw = $entity->get($field);
            $plain = Type::build($type)->toDatabase($raw, $driver);
            $entity->set($field, $this->encrypt($plain));
        }
    }
public function beforeSave ( Event $ event , EntityInterface $ entity ) { $ driver = $ this -> _table -> connection ( ) -> driver ( ) ; foreach ( $ this -> config ( 'fields' ) as $ field => $ type ) { if ( ! $ entity -> has ( $ field ) ) { continue ; } $ raw = $ entity -> get ( $ field ) ; $ plain = Type :: build ( $ type ) -> toDatabase ( $ raw , $ driver ) ; $ entity -> set ( $ field , $ this -> encrypt ( $ plain ) ) ; } }
Event listener to encrypt data.

@param \Cake\Event\Event $event Event.
@param \Cake\Datasource\EntityInterface $entity Entity.
@return void
Event listener to encrypt data .