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

in package

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-2024 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
phpstan-import-type

TEncryptData from Output

Table of Contents

Methods

__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()  : TEncryptData
Get the encryption data array.
getFormattedDate()  : string
Returns a formatted date-time.
getObjectKey()  : string
Compute encryption key depending on object number where the encrypted data is stored.
getPdfEncryptionObj()  : string
Get the PDF encryption block
getUserPermissionCode()  : int
Return the permission code used on encryption (P value).

Methods

__construct()

Set PDF document protection (permission settings)

public __construct([bool $enabled = false ][, string $file_id = '' ][, int $mode = 0 ][, array<string|int, string> $permissions = ['print', 'modify', 'copy', 'annot-forms', 'fill-forms', 'extract', 'assemble', 'print-high'] ][, string $user_pass = '' ][, string $owner_pass = '' ][, array{: array{c: string, p: string[]}}|null $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 = 0

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

$permissions : array<string|int, string> = ['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 = ''

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

$pubkeys : array{: array{c: string, p: string[]}}|null = 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 cert.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

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

encrypt()

Encrypt data using the specified encrypt type.

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

Encrypt type.

$data : string = ''

Data string to encrypt.

$key : string = ''

Encryption key.

$objnum : int = 0

Object number.

Return values
string

encryptString()

Encrypt a string.

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

String to encrypt.

$objnum : int = 0

Object ID.

Return values
string

escapeDataString()

Format a data string for meta information.

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

Data string to escape.

$objnum : int = 0

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(int $protection) : string
Parameters
$protection : int

32bit encryption permission value (P value).

Return values
string

getEncryptionData()

Get the encryption data array.

public getEncryptionData() : TEncryptData
Return values
TEncryptData

getFormattedDate()

Returns a formatted date-time.

public getFormattedDate([int $time = null ][, int $objnum = 0 ]) : 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 = 0

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) : string

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

Parameters
$objnum : int

Object number.

Return values
string

getPdfEncryptionObj()

Get the PDF encryption block

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

Current PDF object number

Return values
string

getUserPermissionCode()

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

public getUserPermissionCode(array<string|int, string> $permissions[, int $mode = 0 ]) : int
Parameters
$permissions : array<string|int, string>

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

$mode : int = 0

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

Return values
int
On this page
 

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