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


PHP Crypto::random方法代码示例

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


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

示例1: testRandom

 function testRandom()
 {
     for ($i = 1; $i < 128; $i += 4) {
         $data = Crypto::random($i);
         $this->assertNotEqual($data, '', 'Empty random data generated');
         $this->assert(strlen($data) == $i, 'Random data received was not the length requested');
     }
 }
开发者ID:pkdevboxy,项目名称:osTicket-1.7,代码行数:8,代码来源:test.crypto.php

示例2: getToken

 function getToken()
 {
     if (!$this->csrf['token'] || $this->isExpired()) {
         $this->csrf['token'] = sha1(session_id() . Crypto::random(16) . SECRET_SALT);
         $this->csrf['time'] = time();
     } else {
         //Reset the timer
         $this->csrf['time'] = time();
     }
     return $this->csrf['token'];
 }
开发者ID:dmiguel92,项目名称:osTicket-1.8,代码行数:11,代码来源:class.csrf.php

示例3: randCode

 function randCode($len = 8, $chars = false)
 {
     $chars = $chars ?: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_=';
     // Determine the number of bits we need
     $char_count = strlen($chars);
     $bits_per_char = ceil(log($char_count, 2));
     $bytes = ceil(4 * $len / floor(32 / $bits_per_char));
     // Pad to 4 byte boundary
     $bytes += (4 - $bytes % 4) % 4;
     // Fetch some random data blocks
     $data = Crypto::random($bytes);
     $mask = (1 << $bits_per_char) - 1;
     $loops = (int) (32 / $bits_per_char);
     $output = '';
     $ints = unpack('V*', $data);
     foreach ($ints as $int) {
         for ($i = $loops; $i > 0; $i--) {
             $output .= $chars[($int & $mask) % $char_count];
             $int >>= $bits_per_char;
         }
     }
     return substr($output, 0, $len);
 }
开发者ID:gizur,项目名称:osticket,代码行数:23,代码来源:class.misc.php

示例4: rotate

 function rotate()
 {
     $this->csrf['token'] = sha1(session_id() . Crypto::random(16) . SECRET_SALT);
     $this->csrf['time'] = time();
 }
开发者ID:gizur,项目名称:osticket,代码行数:5,代码来源:class.csrf.php

示例5: encrypt

 function encrypt($text, $cid = 0)
 {
     if (!$this->exists() || !$text || !($cipher = $this->getCipher($cid)) || !($crypto = $this->getCrypto($cipher['cid']))) {
         return false;
     }
     $ivlen = $cipher['ivlen'];
     $iv = Crypto::random($ivlen);
     $crypto->setKey($this->getKeyHash($iv, $ivlen));
     $crypto->setIV($iv);
     return sprintf('$%s$%s%s', $cipher['cid'], $iv, $crypto->encrypt($text));
 }
开发者ID:KingsleyGU,项目名称:osticket,代码行数:11,代码来源:class.crypto.php


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