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

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:  * AES.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: use \Com\Tecnick\Pdf\Encrypt\Type\AESnopad;
20: 
21: /**
22:  * Com\Tecnick\Pdf\Encrypt\Type\AES
23:  *
24:  * AES
25:  *
26:  * @since       2011-05-23
27:  * @category    Library
28:  * @package     PdfEncrypt
29:  * @author      Nicola Asuni <info@tecnick.com>
30:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
31:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
32:  * @link        https://github.com/tecnickcom/tc-lib-pdf-encrypt
33:  */
34: class AES
35: {
36:     /**
37:      * Encrypt the data using OpenSSL
38:      *
39:      * @param string $data  Data string to encrypt
40:      * @param string $key   Encryption key
41:      * @param string $mode  Cipher
42:      *
43:      * @return string Encrypted data string.
44:      */
45:     public function encrypt($data, $key, $mode = '')
46:     {
47:         if (empty($mode)) {
48:             if (strlen($key) > 16) {
49:                 $mode = 'aes-256-cbc';
50:             } else {
51:                 $mode = 'aes-128-cbc';
52:             }
53:         } elseif (!in_array($mode, array('aes-128-cbc', 'aes-256-cbc'))) {
54:             throw new EncException('unknown chipher: '.$mode);
55:         }
56: 
57:         $ivect = openssl_random_pseudo_bytes(openssl_cipher_iv_length($mode));
58:         $obj = new AESnopad();
59:         return $ivect.$obj->encrypt($data, $key, $ivect, $mode);
60:     }
61: }
62: 
 

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