Total Complexity | 11 |
Total Lines | 118 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class Resource |
||
11 | { |
||
12 | use TraitCryption; |
||
13 | |||
14 | /** |
||
15 | * @var int |
||
16 | */ |
||
17 | private int $length; |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private string $iv; |
||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private string $key; |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private string $dKey; |
||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private string $data; |
||
34 | |||
35 | /** |
||
36 | * @throws Exception |
||
37 | */ |
||
38 | public function __construct() |
||
39 | { |
||
40 | $this->setLength(); |
||
41 | $this->setIv(); |
||
42 | $this->setKey(); |
||
43 | $this->setDKey(); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @return int |
||
48 | */ |
||
49 | protected function getLength(): int |
||
50 | { |
||
51 | return $this->length; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * setLength |
||
56 | */ |
||
57 | private function setLength(): void |
||
58 | { |
||
59 | $this->length = openssl_cipher_iv_length(CIPHERING); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @return string |
||
64 | */ |
||
65 | protected function getIv(): string |
||
66 | { |
||
67 | return $this->iv; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @throws Exception |
||
72 | */ |
||
73 | private function setIv(): void |
||
74 | { |
||
75 | $this->iv = substr(base64_encode(random_bytes($this->getLength())), 0, $this->getLength()); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @return string |
||
80 | */ |
||
81 | protected function getKey(): string |
||
82 | { |
||
83 | return $this->key; |
||
84 | } |
||
85 | |||
86 | |||
87 | /** |
||
88 | * setKey |
||
89 | */ |
||
90 | private function setKey(): void |
||
91 | { |
||
92 | $this->key = base64_encode(DECRYPT_KEY) . $this->getDKey(); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @return string |
||
97 | */ |
||
98 | protected function getDKey(): string |
||
99 | { |
||
100 | return $this->dKey; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * setDKey |
||
105 | */ |
||
106 | private function setDKey(): void |
||
107 | { |
||
108 | $this->dKey = openssl_digest(php_uname(), 'MD5', TRUE); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @return string |
||
113 | */ |
||
114 | protected function getData(): string |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @param string $string |
||
121 | */ |
||
122 | protected function setData(string $string): void |
||
128 | ); |
||
129 | } |
||
130 | |||
131 | } |