public function setProtection($permissions, $userPass = '', $ownerPass = null, $revision = 3)
    {
        if ($revision < 2 || $revision > 3) {
            throw new \InvalidArgumentException('Only revision 2 or 3 are supported.');
        }

        if ($revision === 3) {
            $this->setMinPdfVersion('1.4');
        }

        $this->pValue = $this->sanitizePermissionsValue($permissions, $revision);

        if ($ownerPass === null || $ownerPass === '') {
            $ownerPass = function_exists('random_bytes') ? \random_bytes(32) : uniqid(rand());
        }

        $this->encrypted = true;
        $this->revision = $revision;
        $this->keyLength = $revision === 3 ? 16 : 5;
        $this->padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08"
            . "\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";

        $this->oValue = $this->computeOValue($userPass, $ownerPass);
        $this->encryptionKey = $this->computeEncryptionKey($userPass);
        $this->uValue = $this->computeUValue($this->encryptionKey);

        return $ownerPass;
    }