classes-Com-Tecnick-Pdf-Encrypt-Encrypt

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.

Encrypt extends Compute

Com\Tecnick\Pdf\Encrypt\Encrypt

PHP class for encrypting data for PDF documents

Tags
since
2008-01-02
category

Library

author

Nicola Asuni info@tecnick.com

copyright

2011-2015 Nicola Asuni - Tecnick.com LTD

license

http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)

link
https://github.com/tecnickcom/tc-lib-pdf-encrypt

Table of Contents

$encmap  : array<string|int, mixed>
Define a list of available encrypt encoders.
$encpad  : string
Encryption padding string.
$encrypt_settings  : array<string|int, mixed>
Encryption settings
$encryptdata  : array<string|int, mixed>
Encryption data
$permbits  : array<string|int, mixed>
Map permission modes and bits
__construct()  : mixed
Set PDF document protection (permission settings)
convertHexStringToString()  : string
Convert hexadecimal string to string.
convertStringToHexString()  : string
Convert string to hexadecimal string (byte string).
encodeNameObject()  : string
Encode a name object.
encrypt()  : string
Encrypt data using the specified encrypt type.
encryptString()  : string
Encrypt a string.
escapeDataString()  : string
Format a data string for meta information.
escapeString()  : string
Escape a string: add "\" before "\", "(" and ")".
getEncPermissionsString()  : string
Convert encryption P value to a string of bytes, low-order byte first.
getEncryptionData()  : array<string|int, mixed>
Get the encryption data array.
getFormattedDate()  : string
Returns a formatted date-time.
getObjectKey()  : int
Compute encryption key depending on object number where the encrypted data is stored.
getPdfEncryptionObj()  : mixed
Get the PDF encryption block
getUserPermissionCode()  : int
Return the permission code used on encryption (P value).
generateEncryptionKey()  : mixed
Compute encryption key
generatePublicEncryptionKey()  : mixed
Compute public encryption key
generateStandardEncryptionKey()  : mixed
Compute standard encryption key
getAdditionalEncDic()  : string
get additional encryption dictionary entries for the standard security handler
getBooleanString()  : string
Return a string representation of a boolean value
getCryptFilter()  : string
Get Crypt Filter section
getOEValue()  : string
Compute OE value
getOValue()  : string
Compute O value
getUEValue()  : string
Compute UE value
getUvalue()  : string
Compute U value
setMissingValues()  : mixed
Set missing values

Properties

$encmap

Define a list of available encrypt encoders.

protected static array<string|int, mixed> $encmap = array( 0 => 'RCFourFive', // RC4-40 1 => 'RCFourSixteen', // RC4-128 2 => 'AESSixteen', // AES-128 3 => 'AESThirtytwo', // AES-256 'RC4' => 'RCFour', // RC4-40 'RC4-40' => 'RCFourFive', // RC4-40 'RC4-128' => 'RCFourSixteen', // RC4-128 'AES' => 'AES', // AES-256 'AES-128' => 'AESSixteen', // AES-128 'AES-256' => 'AESThirtytwo', // AES-256 'AESnopad' => 'AESnopad', // AES - no padding 'MD5-16' => 'MDFiveSixteen', // MD5-16 'seed' => 'Seed', )

$encpad

Encryption padding string.

protected static string $encpad = "(�N^Nu�AdNV��..��h>�/��dSiz"

$encrypt_settings

Encryption settings

protected static array<string|int, mixed> $encrypt_settings = array(0 => array( // RC4 40 bit 'V' => 1, 'Length' => 40, 'CF' => array('CFM' => 'V2', 'AuthEvent' => 'DocOpen'), ), 1 => array( // RC4 128 bit 'V' => 2, 'Length' => 128, 'CF' => array('CFM' => 'V2', 'AuthEvent' => 'DocOpen'), 'SubFilter' => 'adbe.pkcs7.s4', 'Recipients' => array(), ), 2 => array( // AES 128 bit 'V' => 4, 'Length' => 128, 'CF' => array('CFM' => 'AESV2', 'Length' => 128, 'AuthEvent' => 'DocOpen'), 'SubFilter' => 'adbe.pkcs7.s5', 'Recipients' => array(), ), 3 => array( // AES 256 bit 'V' => 5, 'Length' => 256, 'CF' => array('CFM' => 'AESV3', 'Length' => 256, 'AuthEvent' => 'DocOpen'), 'SubFilter' => 'adbe.pkcs7.s5', 'Recipients' => array(), ))

$encryptdata

Encryption data

protected array<string|int, mixed> $encryptdata = array('encrypted' => false, 'mode' => false)

$permbits

Map permission modes and bits

protected static array<string|int, mixed> $permbits = array( 'owner' => 2, // bit 2 -- inverted logic: cleared by default // When set permits change of encryption and enables all other permissions. 'print' => 4, // bit 3 // Print the document. 'modify' => 8, // bit 4 // Modify the contents of the document by operations other than those controlled // by 'fill-forms', 'extract' and 'assemble'. 'copy' => 16, // bit 5 // Copy or otherwise extract text and graphics from the document. 'annot-forms' => 32, // bit 6 // Add or modify text annotations, fill in interactive form fields, and, // if 'modify' is also set, create or modify interactive form fields // (including signature fields). 'fill-forms' => 256, // bit 9 // Fill in existing interactive form fields (including signature fields), // even if 'annot-forms' is not specified. 'extract' => 512, // bit 10 // Extract text and graphics (in support of accessibility to users with // disabilities or for other purposes). 'assemble' => 1024, // bit 11 // Assemble the document (insert, rotate, or delete pages and create bookmarks // or thumbnail images), even if 'modify' is not set. 'print-high' => 2048, )

Methods

__construct()

Set PDF document protection (permission settings)

public __construct([bool $enabled = false ][, string $file_id = '' ], int $mode[, array<string|int, mixed> $permissions = array('print', 'modify', 'copy', 'annot-forms', 'fill-forms', 'extract', 'assemble', 'print-high') ][, string $user_pass = '' ][, string $owner_pass = null ][, string $pubkeys = null ]) : mixed

NOTES: The protection against modification is for people who have the full Acrobat product. If you don't set any password, the document will open as usual. If you set a user password, the PDF viewer will ask for it before displaying the document. The master password, if different from the user one, can be used to get full access. Protecting a document requires to encrypt it, which requires long processign time and may cause timeouts.

Parameters
$enabled : bool = false

False if the encryption is disabled (i.e. the document is in PDF/A mode)

$file_id : string = ''

File ID

$mode : int

Encryption strength: 0 = RC4 40; 1 = RC4 128; 2 = AES 128; 3 = AES 256

$permissions : array<string|int, mixed> = array('print', 'modify', 'copy', 'annot-forms', 'fill-forms', 'extract', 'assemble', 'print-high')

The set of permissions (specify the ones you want to block): 'owner' // When set permits change of encryption and enables all other permissions. // (inverted logic: cleared by default). 'print' // Print the document. 'modify' // Modify the contents of the document by operations other than those controlled // by 'fill-forms', 'extract' and 'assemble'. 'copy' // Copy or otherwise extract text and graphics from the document. 'annot-forms' // Add or modify text annotations, fill in interactive form fields, and, // if 'modify' is also set, create or modify interactive form fields // (including signature fields). 'fill-forms' // Fill in existing interactive form fields (including signature fields), // even if 'annot-forms' is not specified. 'extract' // Extract text and graphics (in support of accessibility to users with // disabilities or for other purposes). 'assemble' // Assemble the document (insert, rotate, or delete pages and create bookmarks // or thumbnail images), even if 'modify' is not set. 'print-high' // Print the document to a representation from which a faithful digital copy of the // PDF content could be generated. When this is not set, printing is limited to a // low-level representation of the appearance, possibly of degraded quality.

$user_pass : string = ''

User password. Empty by default.

$owner_pass : string = null

Owner password. If not specified, a random value is used.

$pubkeys : string = null

Array of recipients containing public-key certificates ('c') and permissions ('p'). For example: array(array('c' => 'file://../examples/data/cert/test.crt', 'p' => array('print'))) To create self-signed certificate: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout key.pem -out cert.pem To export crt to p12: openssl pkcs12 -export -in cert.pem -out cert.p12 To convert pfx certificate to pem: openssl pkcs12 -in cert.pfx -out cert.pem -nodes

Return values
mixed

convertHexStringToString()

Convert hexadecimal string to string.

public convertHexStringToString(string $bstr) : string
Parameters
$bstr : string

Byte-string to convert.

Return values
string

convertStringToHexString()

Convert string to hexadecimal string (byte string).

public convertStringToHexString(string $str) : string
Parameters
$str : string

String to convert.

Return values
string

encodeNameObject()

Encode a name object.

public encodeNameObject(string $name) : string
Parameters
$name : string

Name object to encode.

Return values
string

Encoded name object.

encrypt()

Encrypt data using the specified encrypt type.

public encrypt(string $type[, string $data = '' ][, string $key = null ][, int $objnum = null ]) : string
Parameters
$type : string

Encrypt type.

$data : string = ''

Data string to encrypt.

$key : string = null

Encryption key.

$objnum : int = null

Object number.

Return values
string

Encrypted data string.

encryptString()

Encrypt a string.

public encryptString(string $str[, int $objnum = null ]) : string
Parameters
$str : string

String to encrypt.

$objnum : int = null

Object ID.

Return values
string

escapeDataString()

Format a data string for meta information.

public escapeDataString(string $str[, int $objnum = null ]) : string
Parameters
$str : string

Data string to escape.

$objnum : int = null

Object ID.

Return values
string

escapeString()

Escape a string: add "\" before "\", "(" and ")".

public escapeString(string $str) : string
Parameters
$str : string

String to escape.

Return values
string

getEncPermissionsString()

Convert encryption P value to a string of bytes, low-order byte first.

public getEncPermissionsString(string $protection) : string
Parameters
$protection : string

32bit encryption permission value (P value).

Return values
string

getEncryptionData()

Get the encryption data array.

public getEncryptionData() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFormattedDate()

Returns a formatted date-time.

public getFormattedDate([int $time = null ][, int $objnum = null ]) : string
Parameters
$time : int = null

UTC time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

$objnum : int = null

Object ID.

Return values
string

escaped date string.

getObjectKey()

Compute encryption key depending on object number where the encrypted data is stored.

public getObjectKey(int $objnum) : int

This is used for all strings and streams without crypt filter specifier.

Parameters
$objnum : int

Object number.

Return values
int

getPdfEncryptionObj()

Get the PDF encryption block

public getPdfEncryptionObj(int &$pon) : mixed
Parameters
$pon : int

Current PDF object number

return string

Return values
mixed

getUserPermissionCode()

Return the permission code used on encryption (P value).

public getUserPermissionCode(array<string|int, mixed> $permissions,  $mode) : int
Parameters
$permissions : array<string|int, mixed>

The set of permissions (specify the ones you want to block).

$mode :

(int) encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.

Return values
int

generateEncryptionKey()

Compute encryption key

protected generateEncryptionKey() : mixed
Return values
mixed

generatePublicEncryptionKey()

Compute public encryption key

protected generatePublicEncryptionKey() : mixed
Return values
mixed

generateStandardEncryptionKey()

Compute standard encryption key

protected generateStandardEncryptionKey() : mixed
Return values
mixed

getAdditionalEncDic()

get additional encryption dictionary entries for the standard security handler

protected getAdditionalEncDic() : string
Return values
string

getBooleanString()

Return a string representation of a boolean value

protected getBooleanString(bool $value) : string
Parameters
$value : bool

Value to convert

Return values
string

getCryptFilter()

Get Crypt Filter section

protected getCryptFilter() : string

A dictionary whose keys shall be crypt filter names and whose values shall be the corresponding crypt filter dictionaries.

Return values
string

getOEValue()

Compute OE value

protected getOEValue() : string
Return values
string

OE value

getOValue()

Compute O value

protected getOValue() : string
Return values
string

O value

getUEValue()

Compute UE value

protected getUEValue() : string
Return values
string

UE value

getUvalue()

Compute U value

protected getUvalue() : string
Return values
string

U value

setMissingValues()

Set missing values

protected setMissingValues() : mixed
Return values
mixed
 

© 2004-2021 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy