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));
        }
    }