当前位置: 首页>>代码示例>>PHP>>正文


PHP Math_BigInteger::equals方法代码示例

本文整理汇总了PHP中Math_BigInteger::equals方法的典型用法代码示例。如果您正苦于以下问题:PHP Math_BigInteger::equals方法的具体用法?PHP Math_BigInteger::equals怎么用?PHP Math_BigInteger::equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Math_BigInteger的用法示例。


在下文中一共展示了Math_BigInteger::equals方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setPublicKey

 public function setPublicKey($key = false, $type = false)
 {
     if ($key === false && !empty($this->modulus)) {
         $this->publicExponent = $this->exponent;
         return true;
     }
     if ($type === false) {
         $types = array(CRYPT_RSA_PUBLIC_FORMAT_RAW, CRYPT_RSA_PUBLIC_FORMAT_PKCS1, CRYPT_RSA_PUBLIC_FORMAT_XML, CRYPT_RSA_PUBLIC_FORMAT_OPENSSH);
         foreach ($types as $type) {
             $components = $this->_parseKey($key, $type);
             if ($components !== false) {
                 break;
             }
         }
     } else {
         $components = $this->_parseKey($key, $type);
     }
     if ($components === false) {
         return false;
     }
     if (empty($this->modulus) || !$this->modulus->equals($components['modulus'])) {
         $this->modulus = $components['modulus'];
         $this->exponent = $this->publicExponent = $components['publicExponent'];
         return true;
     }
     $this->publicExponent = $components['publicExponent'];
     return true;
 }
开发者ID:fkssei,项目名称:pigcms10,代码行数:28,代码来源:Crypt_RSA.php

示例2: getServerPublicHostKey

 /**
  * Returns the server public host key.
  *
  * Caching this the first time you connect to a server and checking the result on subsequent connections
  * is recommended.  Returns false if the server signature is not signed correctly with the public host key.
  *
  * @return Mixed
  * @access public
  */
 function getServerPublicHostKey()
 {
     if (!($this->bitmap & NET_SSH2_MASK_CONSTRUCTOR)) {
         $this->bitmap |= NET_SSH2_MASK_CONSTRUCTOR;
         if (!$this->_connect()) {
             return false;
         }
     }
     $signature = $this->signature;
     $server_public_host_key = $this->server_public_host_key;
     extract(unpack('Nlength', $this->_string_shift($server_public_host_key, 4)));
     $this->_string_shift($server_public_host_key, $length);
     if ($this->signature_validated) {
         return $this->bitmap ? $this->signature_format . ' ' . base64_encode($this->server_public_host_key) : false;
     }
     $this->signature_validated = true;
     switch ($this->signature_format) {
         case 'ssh-dss':
             $zero = new Math_BigInteger();
             $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4));
             $p = new Math_BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256);
             $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4));
             $q = new Math_BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256);
             $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4));
             $g = new Math_BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256);
             $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4));
             $y = new Math_BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256);
             /* The value for 'dss_signature_blob' is encoded as a string containing
                r, followed by s (which are 160-bit integers, without lengths or
                padding, unsigned, and in network byte order). */
             $temp = unpack('Nlength', $this->_string_shift($signature, 4));
             if ($temp['length'] != 40) {
                 user_error('Invalid signature');
                 return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
             }
             $r = new Math_BigInteger($this->_string_shift($signature, 20), 256);
             $s = new Math_BigInteger($this->_string_shift($signature, 20), 256);
             switch (true) {
                 case $r->equals($zero):
                 case $r->compare($q) >= 0:
                 case $s->equals($zero):
                 case $s->compare($q) >= 0:
                     user_error('Invalid signature');
                     return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
             }
             $w = $s->modInverse($q);
             $u1 = $w->multiply(new Math_BigInteger(sha1($this->exchange_hash), 16));
             list(, $u1) = $u1->divide($q);
             $u2 = $w->multiply($r);
             list(, $u2) = $u2->divide($q);
             $g = $g->modPow($u1, $p);
             $y = $y->modPow($u2, $p);
             $v = $g->multiply($y);
             list(, $v) = $v->divide($p);
             list(, $v) = $v->divide($q);
             if (!$v->equals($r)) {
                 user_error('Bad server signature');
                 return $this->_disconnect(NET_SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE);
             }
             break;
         case 'ssh-rsa':
             $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4));
             $e = new Math_BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256);
             $temp = unpack('Nlength', $this->_string_shift($server_public_host_key, 4));
             $n = new Math_BigInteger($this->_string_shift($server_public_host_key, $temp['length']), -256);
             $nLength = $temp['length'];
             /*
             $temp = unpack('Nlength', $this->_string_shift($signature, 4));
             $signature = $this->_string_shift($signature, $temp['length']);
             
             if (!class_exists('Crypt_RSA')) {
                 include_once 'Crypt/RSA.php';
             }
             
             $rsa = new Crypt_RSA();
             $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
             $rsa->loadKey(array('e' => $e, 'n' => $n), CRYPT_RSA_PUBLIC_FORMAT_RAW);
             if (!$rsa->verify($this->exchange_hash, $signature)) {
                 user_error('Bad server signature');
                 return $this->_disconnect(NET_SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE);
             }
             */
             $temp = unpack('Nlength', $this->_string_shift($signature, 4));
             $s = new Math_BigInteger($this->_string_shift($signature, $temp['length']), 256);
             // validate an RSA signature per "8.2 RSASSA-PKCS1-v1_5", "5.2.2 RSAVP1", and "9.1 EMSA-PSS" in the
             // following URL:
             // ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1.pdf
             // also, see SSHRSA.c (rsa2_verifysig) in PuTTy's source.
             if ($s->compare(new Math_BigInteger()) < 0 || $s->compare($n->subtract(new Math_BigInteger(1))) > 0) {
                 user_error('Invalid signature');
                 return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
//.........这里部分代码省略.........
开发者ID:pacificcasinohotel,项目名称:pointsystem,代码行数:101,代码来源:SSH2.php

示例3: setPublicKey

 /**
  * Defines the public key
  *
  * Some private key formats define the public exponent and some don't.  Those that don't define it are problematic when
  * used in certain contexts.  For example, in SSH-2, RSA authentication works by sending the public key along with a
  * message signed by the private key to the server.  The SSH-2 server looks the public key up in an index of public keys
  * and if it's present then proceeds to verify the signature.  Problem is, if your private key doesn't include the public
  * exponent this won't work unless you manually add the public exponent.
  *
  * Do note that when a new key is loaded the index will be cleared.
  *
  * Returns true on success, false on failure
  *
  * @see getPublicKey()
  * @access public
  * @param String $key
  * @param Integer $type optional
  * @return Boolean
  */
 function setPublicKey($key, $type = CRYPT_RSA_PUBLIC_FORMAT_PKCS1)
 {
     $components = $this->_parseKey($key, $type);
     if (empty($this->modulus) || !$this->modulus->equals($components['modulus'])) {
         return false;
     }
     $this->publicExponent = $components['publicExponent'];
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:27,代码来源:RSA.php

示例4: setPublicKey

 /**
  * Defines the public key
  *
  * Some private key formats define the public exponent and some don't.  Those that don't define it are problematic when
  * used in certain contexts.  For example, in SSH-2, RSA authentication works by sending the public key along with a
  * message signed by the private key to the server.  The SSH-2 server looks the public key up in an index of public keys
  * and if it's present then proceeds to verify the signature.  Problem is, if your private key doesn't include the public
  * exponent this won't work unless you manually add the public exponent.
  *
  * Do note that when a new key is loaded the index will be cleared.
  *
  * Returns true on success, false on failure
  *
  * @see getPublicKey()
  * @access public
  * @param String $key
  * @param Integer $type optional
  * @return Boolean
  */
 function setPublicKey($key, $type = CRYPT_RSA_PUBLIC_FORMAT_PKCS1)
 {
     $components = $this->_parseKey($key, $type);
     if (empty($this->modulus) || !$this->modulus->equals($components['modulus'])) {
         user_error('Trying to load a public key?  Use loadKey() instead.  It\'s called loadKey() and not loadPrivateKey() for a reason.', E_USER_NOTICE);
         return false;
     }
     $this->publicExponent = $components['publicExponent'];
     return true;
 }
开发者ID:nhathong1204,项目名称:bdshungthinh,代码行数:29,代码来源:RSA.php

示例5: setPublicKey

 /**
  * Defines the public key
  *
  * Some private key formats define the public exponent and some don't.  Those that don't define it are problematic when
  * used in certain contexts.  For example, in SSH-2, RSA authentication works by sending the public key along with a
  * message signed by the private key to the server.  The SSH-2 server looks the public key up in an index of public keys
  * and if it's present then proceeds to verify the signature.  Problem is, if your private key doesn't include the public
  * exponent this won't work unless you manually add the public exponent.
  *
  * Do note that when a new key is loaded the index will be cleared.
  *
  * Returns true on success, false on failure
  *
  * @see getPublicKey()
  * @access public
  * @param String $key optional
  * @param Integer $type optional
  * @return Boolean
  */
 function setPublicKey($key = false, $type = false)
 {
     if ($key === false && !empty($this->modulus)) {
         $this->publicExponent = $this->exponent;
         return true;
     }
     if ($type === false) {
         $types = array(CRYPT_RSA_PUBLIC_FORMAT_RAW, CRYPT_RSA_PUBLIC_FORMAT_PKCS1, CRYPT_RSA_PUBLIC_FORMAT_XML, CRYPT_RSA_PUBLIC_FORMAT_OPENSSH);
         foreach ($types as $type) {
             try {
                 $components = $this->_parseKey($key, $type);
                 break;
             } catch (FormatNotSupportedException $e) {
             }
         }
         if (!isset($components)) {
             throw new FormatNotSupportedException('Unable to find matching format');
         }
     } else {
         $components = $this->_parseKey($key, $type);
     }
     if (empty($this->modulus) || !$this->modulus->equals($components['modulus'])) {
         $this->modulus = $components['modulus'];
         $this->exponent = $this->publicExponent = $components['publicExponent'];
         return true;
     }
     $this->publicExponent = $components['publicExponent'];
     return true;
 }
开发者ID:ridwan789,项目名称:phpseclib-php5,代码行数:48,代码来源:RSA.php

示例6: verifyBlindedHash

 /**
  * 
  * @param unknown $text string
  * @param unknown $unblindf string: hex encoded bigInt
  * @param unknown $blindedHash string: hex encoded bigInt
  */
 function verifyBlindedHash($text, $unblindf, $blindedHash)
 {
     $hashByMe = hash('sha256', $text);
     $hashByMeBigInt = new Math_BigInteger($hashByMe, 16);
     $blindedHashBigInt = new Math_BigInteger($blindedHash, 16);
     $signedblindedHash = $this->myPrivateKey['privRsa']->_rsasp1($blindedHashBigInt);
     $unblindf = new Math_BigInteger($unblindf, 16);
     $unblindedSignedHash = $this->myPrivateKey['privRsa']->rsaUnblind($signedblindedHash, $unblindf);
     $verifyHash = $this->myPrivateKey['pubRsa']->_rsasp1($unblindedSignedHash);
     $hashOk = $hashByMeBigInt->equals($verifyHash);
     if ($hashOk !== true) {
         WrongRequestException::throwException(1002, "Error: blinded hash verification failed", "expected hash: {$hashByMe}, got unblinded hash: {$verifyHash}, blinded Hash {$blindedHash}, unblinding factor {$unblindf}");
     }
     return $hashOk;
 }
开发者ID:ppschweiz,项目名称:vvvote,代码行数:21,代码来源:crypt.php


注:本文中的Math_BigInteger::equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。