function _key_exchange() { if (!is_null($this->_key) || $this->_encryptMode == 0) { return true; } $request = "phprpc_encrypt=true&phprpc_keylen={$this->_keylen}"; $result = $this->_post($request); if (is_a($result, 'PHPRPC_Error')) { return $result; } if (array_key_exists('phprpc_keylen', $result)) { $this->_keylen = (int) $result['phprpc_keylen']; } else { $this->_keylen = 128; } if (array_key_exists('phprpc_encrypt', $result)) { $encrypt = unserialize(base64_decode($result['phprpc_encrypt'])); PHPRPC::xxtea(); // require_once('xxtea.php'); $x = BigInt::random($this->_keylen - 1, true); $key = BigInt::powmod(BigInt::dec2num($encrypt['y']), $x, BigInt::dec2num($encrypt['p'])); if ($this->_keylen == 128) { $key = BigInt::num2str($key); } else { $key = pack('H*', md5(BigInt::num2dec($key))); } $this->_key = str_pad($key, 16, "", STR_PAD_LEFT); $encrypt = BigInt::num2dec(BigInt::powmod(BigInt::dec2num($encrypt['g']), $x, BigInt::dec2num($encrypt['p']))); $request = "phprpc_encrypt={$encrypt}"; $result = $this->_post($request); if (is_a($result, 'PHPRPC_Error')) { return $result; } } else { $this->_key = NULL; $this->_encryptMode = 0; } return true; }