1 | <?php |
||||||
2 | |||||||
3 | namespace VersionControl\DoctrineEncryptBundle\Encryptors; |
||||||
4 | |||||||
5 | /** |
||||||
6 | * Class for AES256 encryption. |
||||||
7 | * |
||||||
8 | * @author Victor Melnik <[email protected]> |
||||||
9 | */ |
||||||
10 | class AES256Encryptor implements EncryptorInterface |
||||||
11 | { |
||||||
12 | /** |
||||||
13 | * Secret key for aes algorythm. |
||||||
14 | * |
||||||
15 | * @var string |
||||||
16 | */ |
||||||
17 | private $secretKey; |
||||||
18 | |||||||
19 | /** |
||||||
20 | * Initialization of encryptor. |
||||||
21 | * |
||||||
22 | * @param string $key |
||||||
23 | */ |
||||||
24 | public function __construct($key) |
||||||
25 | { |
||||||
26 | $this->secretKey = $key; |
||||||
27 | } |
||||||
28 | |||||||
29 | /** |
||||||
30 | * Implementation of EncryptorInterface encrypt method. |
||||||
31 | * |
||||||
32 | * @param string $data |
||||||
33 | * |
||||||
34 | * @return string |
||||||
35 | */ |
||||||
36 | public function encrypt($data) |
||||||
37 | { |
||||||
38 | if (defined('PHP_MAJOR_VERSION') && PHP_MAJOR_VERSION >= 7) { |
||||||
39 | $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length("AES-256-ECB")); |
||||||
40 | |||||||
41 | return trim(base64_encode(openssl_encrypt( |
||||||
42 | $data, |
||||||
43 | "AES-256-ECB", |
||||||
44 | $this->secretKey, |
||||||
45 | 0, |
||||||
46 | $iv))); |
||||||
47 | } else { |
||||||
48 | return trim(base64_encode(mcrypt_encrypt( |
||||||
0 ignored issues
–
show
|
|||||||
49 | MCRYPT_RIJNDAEL_256, $this->secretKey, $data, MCRYPT_MODE_ECB, |
||||||
50 | mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND |
||||||
0 ignored issues
–
show
The function
mcrypt_create_iv() has been deprecated: 7.1
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.
Loading history...
The function
mcrypt_get_iv_size() has been deprecated: 7.1
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.
Loading history...
|
|||||||
51 | )))); |
||||||
52 | } |
||||||
53 | } |
||||||
54 | |||||||
55 | /** |
||||||
56 | * Implementation of EncryptorInterface decrypt method. |
||||||
57 | * |
||||||
58 | * @param string $data |
||||||
59 | * |
||||||
60 | * @return string |
||||||
61 | */ |
||||||
62 | public function decrypt($data) |
||||||
63 | { |
||||||
64 | if (defined('PHP_MAJOR_VERSION') && PHP_MAJOR_VERSION >= 7) { |
||||||
65 | $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length("AES-256-ECB")); |
||||||
66 | |||||||
67 | return trim(openssl_decrypt( |
||||||
68 | base64_decode($data), |
||||||
69 | "AES-256-ECB", |
||||||
70 | $this->secretKey, |
||||||
71 | 0, |
||||||
72 | $iv)); |
||||||
73 | } else { |
||||||
74 | return trim(mcrypt_decrypt( |
||||||
0 ignored issues
–
show
The function
mcrypt_decrypt() has been deprecated: 7.1
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.
Loading history...
|
|||||||
75 | MCRYPT_RIJNDAEL_256, $this->secretKey, base64_decode($data), MCRYPT_MODE_ECB, mcrypt_create_iv( |
||||||
0 ignored issues
–
show
The function
mcrypt_create_iv() has been deprecated: 7.1
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.
Loading history...
|
|||||||
76 | mcrypt_get_iv_size( |
||||||
0 ignored issues
–
show
The function
mcrypt_get_iv_size() has been deprecated: 7.1
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.
Loading history...
|
|||||||
77 | MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB |
||||||
78 | ), MCRYPT_RAND |
||||||
79 | ))); |
||||||
80 | } |
||||||
81 | } |
||||||
82 | } |
||||||
83 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.