private function decryptSymmetricKeyWithUserKey($entity)
    {
        $encryptedKey = $entity->getKey();
        $decryptedKey = null;
        $user = $this->getUser();

        if ($user instanceof PKEncryptionEnabledUserInterface && $userKey = $encryptedKey->getKey($user)) {
            $userKey = base64_decode($userKey);
            $privateKey = $this->getPrivateKey();
        }
        elseif ($this->accessChecker->canUseOwnerPrivateKey($entity, $user)) {
            // Check if the logged in user can decrpyt the data without private key
            $vivaUser = $entity->getUserProfile()->getUser();
            $userKey = base64_decode($encryptedKey->getKey($vivaUser));
            $privateKey = $this->keyStore->getPrivateKey($vivaUser);
        }
        else {
            return null;
        }

        $decryptedKey = $this->cryptographyProvider->decryptWithPrivateKey($userKey, $privateKey);

        return $decryptedKey;
    }