public function receiveData(array $sendData) { $data_struct = ['data', 'key', 'signature']; if (array_diff($data_struct, array_keys($sendData))) { throw new \Exception('Data Structure Error'); } try { $AES_secret = $this->RSA->privDecrypt($sendData['key']); \CommonTool::log('AES_secret', $AES_secret); } catch (\Exception $e) { throw new \Exception('Failed To Decode AES Secret'); } if ($this->RSA->verify($sendData['data'], $sendData['signature']) === false) { throw new \Exception('Check Signature Failed'); } $this->AES_secret = $AES_secret; $this->AES->setSecretKey($this->AES_secret); $data = $this->AES->decrypt($sendData['data']); \CommonTool::log('decrypted_data', $data); $data = json_decode($data, true); if (json_last_error() == JSON_ERROR_NONE) { if (\CommonTool::checkSummary($data)) { return $data; } throw new \Exception('CheckSignature Failed'); } else { throw new \Exception('Received Data json_decode Failed'); } }