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;
    }
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;
    }
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 ; }
Set permissions as well as user and owner passwords

@param int|array $permissions An array of permission values (see class constants) or the sum of the constant
values. If a value is present it means that the permission is granted.
@param string $userPass If a user password is set, user will be prompted before document is opened.
@param null $ownerPass If an owner password is set, document can be opened in privilege mode with no
restriction if that password is entered.
@param int $revision The revision number of the security handler (2 = RC4-40bits, 3 = RC4-128bits)
@return string The owner password
Set permissions as well as user and owner passwords