當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。