SetaPDF_Core_SecHandler_AbstractHandler Abstract security handler class for handling PDF encryption features.

File: /SetaPDF v2/Core/SecHandler/AbstractHandler.php

Class hierarchy

Summary

Properties

$_auth

protected boolean SetaPDF_Core_SecHandler_AbstractHandler::$_auth = false

Defines if this security handler is authenticated

$_authMode

protected string|null SetaPDF_Core_SecHandler_AbstractHandler::$_authMode

The auth mode

Says who is authenticated: user or owner

$_document

protected SetaPDF_Core_Document SetaPDF_Core_SecHandler_AbstractHandler::$_document

The document to which this security handler is attached

$_encryptMetadata

protected boolean SetaPDF_Core_SecHandler_AbstractHandler::$_encryptMetadata = true

Metadata are encrypted or not

$_encryptionDictionary

protected SetaPDF_Core_Type_Dictionary SetaPDF_Core_SecHandler_AbstractHandler::$_encryptionDictionary

The encryption dictionary

$_encryptionKey

protected string SetaPDF_Core_SecHandler_AbstractHandler::$_encryptionKey

The encryption key

$_keyLength

protected integer SetaPDF_Core_SecHandler_AbstractHandler::$_keyLength = 5

The key length in bytes

This value is still needed if crypt filters are in use: - It is needed to compute the encryption key. - It is needed to compute the O value It is NOT documented which key length should be used for this things if a crypt filter is in use.

$_streamAlgorithm

protected array SetaPDF_Core_SecHandler_AbstractHandler::$_streamAlgorithm = array(...)

The algorithm an key length to be used for en/decrypting stream

$_stringAlgorithm

protected array SetaPDF_Core_SecHandler_AbstractHandler::$_stringAlgorithm = array(...)

The algorithm an key length to be used for en/decrypting strings


Methods

__construct()

The constructor.

Parameters
$document : SetaPDF_Core_Document
 
$encryptionDictionary : SetaPDF_Core_Type_Dictionary
 
Exceptions

Throws SetaPDF_Core_SecHandler_Exception

_computeHashR6()

protected SetaPDF_Core_SecHandler_AbstractHandler::_computeHashR6 (
string $data, string $inputPassword [, string $userKey = '' ]
): string

Computes a hash for security handler revision 6.

Parameters
$data : string
 
$inputPassword : string
 
$userKey : string
 

_crypt()

protected SetaPDF_Core_SecHandler_AbstractHandler::_crypt (
string $data, array $algorithm [, SetaPDF_Core_Type_IndirectObject $param = null [, boolean $encrypt = true ]]
): string

Encrypts or decrypts data using Algorithm 1 of the PDF specification.

Parameters
$data : string
 
$algorithm : array
 
$param : SetaPDF_Core_Type_IndirectObject
 
$encrypt : boolean
 
Exceptions

Throws SetaPDF_Core_SecHandler_Exception

decryptStream()

Decrypt a stream.

Parameters
$data : string
 
$param : SetaPDF_Core_Type_IndirectObject
 
Exceptions

Throws SetaPDF_Core_SecHandler_Exception

decryptString()

Decrypt a string.

Parameters
$data : string
 
$param : SetaPDF_Core_Type_IndirectObject
 
Exceptions

Throws SetaPDF_Core_SecHandler_Exception

encryptStream()

Encrypt a stream.

Parameters
$data : string
 
$param : SetaPDF_Core_Type_IndirectObject
 
Exceptions

Throws SetaPDF_Core_SecHandler_Exception

encryptString()

Encrypt a string.

Parameters
$data : string
 
$param : SetaPDF_Core_Type_IndirectObject
 
Exceptions

Throws SetaPDF_Core_SecHandler_Exception

generateRandomBytes()

Generate random bytes.

Internally the method tries to use PHPs internal available methods for pseudo-random bytes creation: random_bytes(), openssl_random_pseudo_bytes(), mcrypt_create_iv(). If none of these methods is available a random string is generated by using mt_rand().

Parameters
$length
 

getAuthMode()

Get the auth method.

Return Values

"user", "owner" or an empty string if not authenticated.

getDocument()

Returns the document instance of this security handler.

getEncryptMetadata()

Returns true if the metadata are/will be encrypted.

getEncryptionDictionary()

getEncryptionKey()

Get the encryption key if known/authenticated.

Exceptions

Throws SetaPDF_Core_SecHandler_Exception

getPdfVersion()

Get the PDF version, which is needed for the currently used encryption algorithm.

Exceptions

Throws SetaPDF_Exception_NotImplemented

getPermission()

public SetaPDF_Core_SecHandler_AbstractHandler::getPermission (
integer $permission
): boolean

Queries if a permission is granted.

Parameters
$permission : integer
 

getStreamAlgorithm()

Get the stream algorithm data.

getStringAlgorithm()

Get the string algorithm data.

isAuth()

Queries if the security handler is authenticated.

If not it tries by calling auth() without a password.