source-class-Com.Tecnick.Pdf.Encrypt.Type.AESnopad

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.
 1: <?php
 2: /**
 3:  * AESnopad.php
 4:  *
 5:  * @since       2011-05-23
 6:  * @category    Library
 7:  * @package     PdfEncrypt
 8:  * @author      Nicola Asuni <info@tecnick.com>
 9:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
11:  * @link        https://github.com/tecnickcom/tc-lib-pdf-encrypt
12:  *
13:  * This file is part of tc-lib-pdf-encrypt software library.
14:  */
15: 
16: namespace Com\Tecnick\Pdf\Encrypt\Type;
17: 
18: use \Com\Tecnick\Pdf\Encrypt\Exception as EncException;
19: 
20: /**
21:  * Com\Tecnick\Pdf\Encrypt\Type\AESnopad
22:  *
23:  * AES no-padding
24:  *
25:  * @since       2011-05-23
26:  * @category    Library
27:  * @package     PdfEncrypt
28:  * @author      Nicola Asuni <info@tecnick.com>
29:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
30:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
31:  * @link        https://github.com/tecnickcom/tc-lib-pdf-encrypt
32:  */
33: class AESnopad
34: {
35:     /**
36:      * Block size (IV length):
37:      * openssl_cipher_iv_length('aes-256-cbc')
38:      */
39:     const BLOCKSIZE = 16;
40: 
41:     /**
42:      * Initialization Vector (16 bytes)
43:      */
44:     const IVECT = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
45: 
46:     /**
47:      * Encrypt the data
48:      *
49:      * @param string $data  Data string to encrypt
50:      * @param string $key   Encryption key
51:      * @param string $ivect Initialization vector
52:      * @param string $mode  Cipher
53:      *
54:      * @return string Encrypted data string.
55:      */
56:     public function encrypt($data, $key, $ivect = self::IVECT, $mode = 'aes-256-cbc')
57:     {
58:         return substr(
59:             openssl_encrypt(
60:                 $this->pad($data, self::BLOCKSIZE),
61:                 $mode,
62:                 $this->pad($key, (2 * self::BLOCKSIZE)),
63:                 OPENSSL_RAW_DATA,
64:                 $ivect
65:             ),
66:             0,
67:             -16
68:         );
69:     }
70: 
71:     /**
72:      * Pad the input string to the specified length
73:      * (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0)
74:      *
75:      * @param string $data   Data to pad
76:      * @param int    $length Padding length
77:      * @param string $ivect Initialization vector
78:      *
79:      * @return string
80:      */
81:     protected function pad($data, $length)
82:     {
83:         $padding = ($length - (strlen($data) % $length));
84:         return substr($data.str_repeat("\x00", $padding), 0, $length);
85:     }
86: }
87: 
 

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