1 | <?php |
||||||
2 | |||||||
3 | namespace Erykai\Cryption; |
||||||
4 | |||||||
5 | use Exception; |
||||||
6 | |||||||
7 | trait TraitCryption |
||||||
8 | { |
||||||
9 | protected function encryption(string $string): string |
||||||
10 | { |
||||||
11 | $this->setData($string); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
12 | $base = $this->getData(); |
||||||
0 ignored issues
–
show
It seems like
getData() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
13 | |||||||
14 | return bin2hex($base); |
||||||
15 | } |
||||||
16 | |||||||
17 | protected function decryption(string $encryption): ?string |
||||||
18 | { |
||||||
19 | if (!ctype_xdigit($encryption)) { |
||||||
20 | return null; |
||||||
21 | } |
||||||
22 | if (strlen($encryption) % 2 !== 0) { |
||||||
23 | return null; |
||||||
24 | } |
||||||
25 | |||||||
26 | $encryption = hex2bin($encryption); |
||||||
27 | |||||||
28 | $encryption = base64_decode($encryption); |
||||||
29 | [$encrypted_data, $decryption_key, $encryption_iv] = explode(".", $encryption); |
||||||
30 | |||||||
31 | $encryption_iv = hex2bin($encryption_iv); |
||||||
32 | |||||||
33 | $combined_key = CRYPTION_KEY . hex2bin($decryption_key); |
||||||
34 | |||||||
35 | return openssl_decrypt($encrypted_data, CRYPTION_CIPHERING, |
||||||
36 | $combined_key, 0, $encryption_iv); |
||||||
37 | } |
||||||
38 | |||||||
39 | |||||||
40 | } |
||||||
41 |