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


PHP Auth_OpenID_CryptUtil::getBytes方法代码示例

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


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

示例1: test_cryptrand

 function test_cryptrand()
 {
     // It's possible, but HIGHLY unlikely that a correct
     // implementation will fail by returning the same number twice
     $s = Auth_OpenID_CryptUtil::getBytes(32);
     $t = Auth_OpenID_CryptUtil::getBytes(32);
     $this->assertEquals(Auth_OpenID::bytes($s), 32);
     $this->assertEquals(Auth_OpenID::bytes($t), 32);
     $this->assertFalse($s == $t);
 }
开发者ID:Stony-Brook-University,项目名称:doitsbu,代码行数:10,代码来源:CryptUtil.php

示例2: randomString

 /**
  * Produce a string of length random bytes, chosen from chrs.  If
  * $chrs is null, the resulting string may contain any characters.
  *
  * @param integer $length The length of the resulting
  * randomly-generated string
  * @param string $chrs A string of characters from which to choose
  * to build the new string
  * @return string $result A string of randomly-chosen characters
  * from $chrs
  */
 function randomString($length, $population = null)
 {
     if ($population === null) {
         return Auth_OpenID_CryptUtil::getBytes($length);
     }
     $popsize = strlen($population);
     if ($popsize > 256) {
         $msg = 'More than 256 characters supplied to ' . __FUNCTION__;
         trigger_error($msg, E_USER_ERROR);
     }
     $duplicate = 256 % $popsize;
     $str = "";
     for ($i = 0; $i < $length; $i++) {
         do {
             $n = ord(Auth_OpenID_CryptUtil::getBytes(1));
         } while ($n < $duplicate);
         $n %= $popsize;
         $str .= $population[$n];
     }
     return $str;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:32,代码来源:CryptUtil.php

示例3: createAssociation

	/**
	 * Make a new association.
	 */
	function createAssociation($dumb = true, $assoc_type = 'HMAC-SHA1')
	{
		$secret = Auth_OpenID_CryptUtil::getBytes(
		Auth_OpenID_getSecretSize($assoc_type));

		$uniq = base64_encode(Auth_OpenID_CryptUtil::getBytes(4));
		$handle = sprintf('{%s}{%x}{%s}', $assoc_type, intval(time()), $uniq);

		$assoc = Auth_OpenID_Association::fromExpiresIn(
		$this->SECRET_LIFETIME, $handle, $secret, $assoc_type);

		if ($dumb) {
			$key = $this->dumb_key;
		} else {
			$key = $this->normal_key;
		}

		$this->store->storeAssociation($key, $assoc);
		return $assoc;
	}
开发者ID:hoalangoc,项目名称:ftf,代码行数:23,代码来源:Server.php

示例4: rand

 /**
  * Returns a random number in the specified range.  This function
  * accepts $start, $stop, and $step values of arbitrary magnitude
  * and will utilize the local large-number math library when
  * available.
  *
  * @param integer $start The start of the range, or the minimum
  * random number to return
  * @param integer $stop The end of the range, or the maximum
  * random number to return
  * @param integer $step The step size, such that $result - ($step
  * * N) = $start for some N
  * @return integer $result The resulting randomly-generated number
  */
 function rand($stop)
 {
     static $duplicate_cache = array();
     // Used as the key for the duplicate cache
     $rbytes = $this->longToBinary($stop);
     if (array_key_exists($rbytes, $duplicate_cache)) {
         list($duplicate, $nbytes) = $duplicate_cache[$rbytes];
     } else {
         if ($rbytes[0] == "") {
             $nbytes = Auth_OpenID::bytes($rbytes) - 1;
         } else {
             $nbytes = Auth_OpenID::bytes($rbytes);
         }
         $mxrand = $this->pow(256, $nbytes);
         // If we get a number less than this, then it is in the
         // duplicated range.
         $duplicate = $this->mod($mxrand, $stop);
         if (count($duplicate_cache) > 10) {
             $duplicate_cache = array();
         }
         $duplicate_cache[$rbytes] = array($duplicate, $nbytes);
     }
     do {
         $bytes = "" . Auth_OpenID_CryptUtil::getBytes($nbytes);
         $n = $this->binaryToLong($bytes);
         // Keep looping if this value is in the low duplicated range
     } while ($this->cmp($n, $duplicate) < 0);
     return $this->mod($n, $stop);
 }
开发者ID:ookwudili,项目名称:chisimba,代码行数:43,代码来源:BigMath.php


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