private function processEntity($entity, $operation)
    {
        if ($this->settings[$operation.'_on_backend']) {

            $reflection = ClassUtils::newReflectionObject($entity);
            $classMetadata = $this->getEncryptionMetadataFor($reflection->getName());
            if ($classMetadata->encryptionEnabled && $this->toProcess($entity, $operation)) {
                // Get the encryption key data
                $keyData = $this->keyManager->getEntityEncryptionKeyData($entity);
                if ($keyData) {
                    // get the encrypted fields
                    $encryptionEnabledFields = $this->getEncryptionEnabledFields($reflection);

                    // Encrypt the fields
                    foreach ($encryptionEnabledFields as $fieldName => $field) {
                        $fieldEncrypter = $this->getFieldEncrypter($field, $reflection);
                        $value = $this->getFieldValue($entity, $field);
                        $processedValue = $fieldEncrypter->{$operation}($value, $keyData);
                        $this->setFieldValue($entity, $field, $processedValue);
                    }

                    // Set the encryption flag
                    $entity->setEncrypted($operation === self::ENCRYPT);

                    // If this entity has an encryptable file, process it
                    if ($this->isEncryptableFile($entity) && $this->toProcessFile($entity, $operation)) {
                        $method = $operation.'File';
                        $this->{$method}($entity, $keyData);
                    }
                }
            }
        }
    }