SetaPDF_Core_SecHandler Main class for PDF security handlers

File: /SetaPDF v2/Core/SecHandler.php

Class hierarchy

Summary

Constants

AES

public const integer SetaPDF_Core_SecHandler::AES = 32

Encryption constant

AES_128

public const integer SetaPDF_Core_SecHandler::AES_128 = 96

Encryption constant

AES_256

public const integer SetaPDF_Core_SecHandler::AES_256 = 160

Encryption constant

ARCFOUR

public const integer SetaPDF_Core_SecHandler::ARCFOUR = 4

Encryption constant

ARCFOUR_128

public const integer SetaPDF_Core_SecHandler::ARCFOUR_128 = 20

Encryption constant

ARCFOUR_40

public const integer SetaPDF_Core_SecHandler::ARCFOUR_40 = 12

Encryption constant

OWNER

public const string SetaPDF_Core_SecHandler::OWNER = 'owner'

Owner auth mode

PERM_ACCESSIBILITY

public const integer SetaPDF_Core_SecHandler::PERM_ACCESSIBILITY = 512

Permission constant.

For handlers of revision 3 or greater: Extract text and graphics (in support of accessibility to users with disabilities or for other purposes).

See
  • PDF 32000-1:2008 - Table 22 - User access permissions

PERM_ANNOT

public const integer SetaPDF_Core_SecHandler::PERM_ANNOT = 32

Permission constant.

Add or modify text annotations, fill in interactive form fields, and, if SetaPDF_Core_SecHandler::PERM_MODIFY is also set, create or modify interactive form fields (including signature fields).

See
  • PDF 32000-1:2008 - Table 22 - User access permissions

PERM_ASSEMBLE

public const integer SetaPDF_Core_SecHandler::PERM_ASSEMBLE = 1024

Permission constant.

For handlers of revision 3 or greater: Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if SetaPDF_Core_SecHandler::PERM_MODIFY is not set.

See
  • PDF 32000-1:2008 - Table 22 - User access permissions

PERM_COPY

public const integer SetaPDF_Core_SecHandler::PERM_COPY = 16

Permission constant.

For handlers of revision 2: Copy or otherwise extract text and graphics from the document, including extracting text and graphics (in support of accessibility to users with disabilities or for other purposes).

For handlers of revision 3 or greater: Copy or otherwise extract text and graphics from the document by operations other than that controlled by bit SetaPDF_Core_SecHandler::PERM_ACCESSIBILITY.

See
  • PDF 32000-1:2008 - Table 22 - User access permissions

PERM_DIGITAL_PRINT

public const integer SetaPDF_Core_SecHandler::PERM_DIGITAL_PRINT = 2048

Permission constant.

Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set (and SetaPDF_Core_SecHandler::PERM_PRINT is set), printing is limited to a low-level representation of the appearance, possibly of degraded quality.

See
  • PDF 32000-1:2008 - Table 22 - User access permissions

PERM_FILL_FORM

public const integer SetaPDF_Core_SecHandler::PERM_FILL_FORM = 256

Permission constant.

For handlers of revision 3 or greater: Fill in existing interactive form fields (including signature fields), even if SetaPDF_Core_SecHandler::PERM_ANNOT is not set.

See
  • PDF 32000-1:2008 - Table 22 - User access permissions

PERM_MODIFY

public const integer SetaPDF_Core_SecHandler::PERM_MODIFY = 8

Permission constant.

Modify the contents of the document by operations other than those controlled by SetaPDF_Core_SecHandler::PERM_ANNOT, SetaPDF_Core_SecHandler::PERM_FILL_FORM and SetaPDF_Core_SecHandler::PERM_ASSEMBLE.

See
  • PDF 32000-1:2008 - Table 22 - User access permissions

PERM_PRINT

public const integer SetaPDF_Core_SecHandler::PERM_PRINT = 4

Permission constant.

For handlers of revision 2: Print the document.

Handlers of a revision of 3 or greater: Print the document (possibly not at the highest quality level, depending on whether SetaPDF_Core_SecHandler::PERM_DIGITAL_PRINT is also set).

See
  • PDF 32000-1:2008 - Table 22 - User access permissions

PUB_KEY

public const string SetaPDF_Core_SecHandler::PUB_KEY = 'publicKey'

Public Key Security Handler

STANDARD

public const string SetaPDF_Core_SecHandler::STANDARD = 'standard'

Standard Security Handler

USER

public const string SetaPDF_Core_SecHandler::USER = 'user'

User auth mode


Static Properties

$engine

static public string SetaPDF_Core_SecHandler::$engine = 'openssl'

The encryption engine to use (mcrypt or openssl).


Static Methods

aes128Decrypt()

public static SetaPDF_Core_SecHandler::aes128Decrypt (
string $key, string $data
): string

Decrypts data using AES 128 bit algorithm.

Parameters
$key : string
 
$data : string
 

aes128Encrypt()

public static SetaPDF_Core_SecHandler::aes128Encrypt (
string $key, string $data
): string

Encrypts data using AES 128 bit algorithm.

Parameters
$key : string
 
$data : string
 

aes256Decrypt()

public static SetaPDF_Core_SecHandler::aes256Decrypt (
string $key, string $data
): string

Decrypts data using AES 256 bit algorithm.

Parameters
$key : string
 
$data : string
 

aes256Encrypt()

public static SetaPDF_Core_SecHandler::aes256Encrypt (
string $key, string $data
): string

Encrypts data using AES 256 bit algorithm.

Parameters
$key : string
 
$data : string
 

arcfour()

public static SetaPDF_Core_SecHandler::arcfour (
string $key, string $data
): string

Encrypts or decrypts data using the RC4/Arcfour algorithm.

Parameters
$key : string
 
$data : string
 

checkPermission()

public static SetaPDF_Core_SecHandler::checkPermission (
SetaPDF_Core_Document $document, integer $permission [, null|string $message = null ]
): bool

Checks a permission against the security handler of a document.

Parameters
$document : SetaPDF_Core_Document

The document instance

$permission : integer

Permission to check

$message : null|string

Custom error message

Exceptions

Throws SetaPDF_Core_SecHandler_Exception if no rights are granted for the permission.

factory()

Returns a standard predefined security handler.

The type parameter will define things like algorithm and key length. Additionally the type could be an encryption dictionary, which will setup the desired security handler.

Parameters
$document : SetaPDF_Core_Document
 
$encryptionDictionary : SetaPDF_Core_Type_Dictionary
 
Exceptions

Throws SetaPDF_Core_Exception

Throws SetaPDF_Exception_NotImplemented

generateRandomBytes()

public static SetaPDF_Core_SecHandler::generateRandomBytes (
int $length
): string

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 : int
 
Exceptions

Throws SetaPDF_Core_SecHandler_Exception

Throws Exception