1 | <?php |
||
16 | abstract class AESCBCAlgorithm implements ContentEncryptionAlgorithm |
||
17 | { |
||
18 | /** |
||
19 | * Get cipher method name that is recognized by OpenSSL. |
||
20 | * |
||
21 | * @return string |
||
22 | */ |
||
23 | abstract protected function _cipherMethod(): string; |
||
24 | |||
25 | /** |
||
26 | * Get algorithm name that is recognized by the Hash extension. |
||
27 | * |
||
28 | * @return string |
||
29 | */ |
||
30 | abstract protected function _hashAlgo(): string; |
||
31 | |||
32 | /** |
||
33 | * Get length of the encryption key. |
||
34 | * |
||
35 | * @return int |
||
36 | */ |
||
37 | abstract protected function _encKeyLen(): int; |
||
38 | |||
39 | /** |
||
40 | * Get length of the MAC key. |
||
41 | * |
||
42 | * @return int |
||
43 | */ |
||
44 | abstract protected function _macKeyLen(): int; |
||
45 | |||
46 | /** |
||
47 | * Get length of the authentication tag. |
||
48 | * |
||
49 | * @return int |
||
50 | */ |
||
51 | abstract protected function _tagLen(): int; |
||
52 | |||
53 | /** |
||
54 | * Get cipher method and verify that it's supported. |
||
55 | * |
||
56 | * @throws \RuntimeException |
||
57 | * @return string |
||
58 | */ |
||
59 | 38 | final protected function _getCipherMethod(): string |
|
73 | |||
74 | /** |
||
75 | * Check that key is valid. |
||
76 | * |
||
77 | * @param string $key |
||
78 | * @throws \RuntimeException |
||
79 | */ |
||
80 | 39 | final protected function _validateKey(string $key) |
|
86 | |||
87 | /** |
||
88 | * Check that IV is valid. |
||
89 | * |
||
90 | * @param string $iv |
||
91 | * @throws \RuntimeException |
||
92 | */ |
||
93 | 38 | final protected function _validateIV(string $iv) |
|
100 | |||
101 | /** |
||
102 | * Get MAC key from CEK. |
||
103 | * |
||
104 | * @param string $key |
||
105 | * @return string |
||
106 | */ |
||
107 | 36 | final protected function _macKey(string $key): string |
|
111 | |||
112 | /** |
||
113 | * Get encryption key from CEK. |
||
114 | * |
||
115 | * @param string $key |
||
116 | * @return string |
||
117 | */ |
||
118 | 36 | final protected function _encKey(string $key): string |
|
122 | |||
123 | /** |
||
124 | * Compute AL value. |
||
125 | * |
||
126 | * @param string $aad |
||
127 | * @return string 64 bits |
||
128 | */ |
||
129 | 36 | final protected function _aadLen(string $aad): string |
|
137 | |||
138 | /** |
||
139 | * Compute authentication tag. |
||
140 | * |
||
141 | * @param string $data |
||
142 | * @param string $key CEK |
||
143 | * @return string |
||
144 | */ |
||
145 | 36 | final protected function _computeAuthTag(string $data, string $key): string |
|
150 | |||
151 | /** |
||
152 | * |
||
153 | * {@inheritdoc} |
||
154 | */ |
||
155 | 23 | public function encrypt(string $plaintext, string $key, string $iv, |
|
170 | |||
171 | /** |
||
172 | * |
||
173 | * {@inheritdoc} |
||
174 | */ |
||
175 | 17 | public function decrypt(string $ciphertext, string $key, string $iv, |
|
192 | |||
193 | /** |
||
194 | * Get last OpenSSL error message. |
||
195 | * |
||
196 | * @return string|null |
||
197 | */ |
||
198 | 1 | protected function _getLastOpenSSLError() |
|
206 | |||
207 | /** |
||
208 | * |
||
209 | * {@inheritdoc} |
||
210 | */ |
||
211 | 13 | public function ivSize(): int |
|
215 | |||
216 | /** |
||
217 | * |
||
218 | * {@inheritdoc} |
||
219 | */ |
||
220 | 11 | public function headerParameters(): array |
|
224 | } |
||
225 |