1 | <?php |
||
13 | class Encryptor |
||
14 | { |
||
15 | /** |
||
16 | * ID. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $id; |
||
21 | |||
22 | /** |
||
23 | * Token. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $token; |
||
28 | |||
29 | /** |
||
30 | * AES key. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $AESKey; |
||
35 | |||
36 | /** |
||
37 | * Block size. |
||
38 | * |
||
39 | * @var int |
||
40 | */ |
||
41 | protected $blockSize; |
||
42 | |||
43 | /** |
||
44 | * Constructor. |
||
45 | * |
||
46 | * @param string $id |
||
47 | * @param string $token |
||
48 | * @param string $AESKey |
||
49 | * |
||
50 | * @throws RuntimeException |
||
51 | */ |
||
52 | public function __construct($id, $token, $AESKey) |
||
63 | |||
64 | /** |
||
65 | * Encrypt the message and return XML. |
||
66 | * |
||
67 | * @param string $xml |
||
68 | * @param string $nonce |
||
69 | * @param int $timestamp |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | public function encryptMsg($xml, $nonce = null, $timestamp = null) |
||
93 | |||
94 | /** |
||
95 | * Decrypt message. |
||
96 | * |
||
97 | * @param string $msgSignature |
||
98 | * @param string $nonce |
||
99 | * @param string $timestamp |
||
100 | * @param string $postXML |
||
101 | * |
||
102 | * @throws EncryptionException |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | public function decryptMsg($msgSignature, $nonce, $timestamp, $postXML) |
||
124 | |||
125 | /** |
||
126 | * Get SHA1. |
||
127 | * |
||
128 | * @throws EncryptionException |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | public function getSHA1() |
||
143 | |||
144 | /** |
||
145 | * Encode string. |
||
146 | * |
||
147 | * @param string $text |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | public function encode($text) |
||
167 | |||
168 | /** |
||
169 | * Decode string. |
||
170 | * |
||
171 | * @param string $decrypted |
||
172 | * |
||
173 | * @return string |
||
174 | */ |
||
175 | public function decode($decrypted) |
||
185 | |||
186 | /** |
||
187 | * Return AESKey. |
||
188 | * |
||
189 | * @throws InvalidConfigException |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | protected function getAESKey() |
||
205 | |||
206 | /** |
||
207 | * Encrypt string. |
||
208 | * |
||
209 | * @param string $text |
||
210 | * @param string $corpId |
||
211 | * |
||
212 | * @throws EncryptionException |
||
213 | * |
||
214 | * @return string |
||
215 | */ |
||
216 | private function encrypt($text, $corpId) |
||
232 | |||
233 | /** |
||
234 | * Decrypt message. |
||
235 | * |
||
236 | * @param string $encrypted |
||
237 | * @param string $corpId |
||
238 | * |
||
239 | * @throws EncryptionException |
||
240 | * |
||
241 | * @return string |
||
242 | */ |
||
243 | public function decrypt($encrypted, $corpId) |
||
277 | |||
278 | /** |
||
279 | * Generate random string. |
||
280 | * |
||
281 | * @return string |
||
282 | */ |
||
283 | private function getRandomStr() |
||
287 | } |
||
288 |