本文整理汇总了PHP中bigint_random函数的典型用法代码示例。如果您正苦于以下问题:PHP bigint_random函数的具体用法?PHP bigint_random怎么用?PHP bigint_random使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bigint_random函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _key_exchange
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']));
require_once 'bigint.php';
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;
}
示例2: keyExchange
function keyExchange()
{
require_once '../../ThirdParty/ThinkPHP/Extend/Vendor/phpRPC/bigint.php';
$this->initKeylen();
if (isset($_SESSION[$this->cid])) {
$session = unserialize(base64_decode($_SESSION[$this->cid]));
} else {
$session = array();
}
if ($this->encrypt === true) {
require_once '../../ThirdParty/ThinkPHP/Extend/Vendor/phpRPC/dhparams.php';
$DHParams = new DHParams($this->keylen);
$this->keylen = $DHParams->getL();
$encrypt = $DHParams->getDHParams();
$x = bigint_random($this->keylen - 1, true);
$session['x'] = bigint_num2dec($x);
$session['p'] = $encrypt['p'];
$session['keylen'] = $this->keylen;
$encrypt['y'] = bigint_num2dec(bigint_powmod(bigint_dec2num($encrypt['g']), $x, bigint_dec2num($encrypt['p'])));
$this->buffer .= "phprpc_encrypt=\"" . $this->encodeString(serialize_fix($encrypt)) . "\";\r\n";
if ($this->keylen != 128) {
$this->buffer .= "phprpc_keylen=\"{$this->keylen}\";\r\n";
}
$this->sendURL();
} else {
$y = bigint_dec2num($this->encrypt);
$x = bigint_dec2num($session['x']);
$p = bigint_dec2num($session['p']);
$key = bigint_powmod($y, $x, $p);
if ($this->keylen == 128) {
$key = bigint_num2str($key);
} else {
$key = pack('H*', md5(bigint_num2dec($key)));
}
$session['key'] = str_pad($key, 16, "", STR_PAD_LEFT);
}
$_SESSION[$this->cid] = base64_encode(serialize($session));
$this->sendCallback();
}