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


PHP JCrypt::genRandomBytes方法代码示例

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


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

示例1: testGenRandomBytes

 /**
  * @covers JCrypt::genRandomBytes
  */
 public function testGenRandomBytes()
 {
     // We're just testing wether the value has the expected length,
     // we obviously can't test the result since it's random.
     $randomBytes16 = JCrypt::genRandomBytes();
     $this->assertEquals(strlen($randomBytes16), 16);
     $randomBytes8 = JCrypt::genRandomBytes(8);
     $this->assertEquals(strlen($randomBytes8), 8);
     $randomBytes17 = JCrypt::genRandomBytes(17);
     $this->assertEquals(strlen($randomBytes17), 17);
 }
开发者ID:rvsjoen,项目名称:joomla-platform,代码行数:14,代码来源:JCryptTest.php

示例2: generateKey

 protected static function generateKey()
 {
     jimport('joomla.crypt.crypt');
     $key = JCrypt::genRandomBytes(32);
     $salt = md5_file(JPATH_SITE . '/configuration.php');
     $key = base64_encode(self::pbkdf2($key, $salt, 32));
     $filecontents = "<?php defined('WF_EDITOR') or die(); define('WF_SERVERKEY', '{$key}'); ?>";
     $filename = JPATH_COMPONENT_ADMINISTRATOR . '/serverkey.php';
     $result = JFile::write($filename, $filecontents);
     if (!$result) {
         return '';
     } else {
         return base64_decode($key);
     }
 }
开发者ID:jimyb3,项目名称:mathematicalteachingsite,代码行数:15,代码来源:encrypt.php

示例3: isOwner

 /**
  * Method to determine if script owns the path.
  *
  * @param   string  $path  Path to check ownership.
  *
  * @return  boolean  True if the php script owns the path passed.
  *
  * @since   11.1
  */
 public static function isOwner($path)
 {
     jimport('joomla.filesystem.file');
     $tmp = md5(JCrypt::genRandomBytes());
     $ssp = ini_get('session.save_path');
     $jtp = JPATH_SITE . '/tmp';
     // Try to find a writable directory
     $dir = is_writable('/tmp') ? '/tmp' : false;
     $dir = !$dir && is_writable($ssp) ? $ssp : false;
     $dir = !$dir && is_writable($jtp) ? $jtp : false;
     if ($dir) {
         $fileObject = new JFilesystemWrapperFile();
         $test = $dir . '/' . $tmp;
         // Create the test file
         $blank = '';
         $fileObject->write($test, $blank, false);
         // Test ownership
         $return = fileowner($test) == fileowner($path);
         // Delete the test file
         $fileObject->delete($test);
         return $return;
     }
     return false;
 }
开发者ID:b-dur,项目名称:joomla-cms,代码行数:33,代码来源:path.php

示例4: generateKey

 /**
  * Method to generate a new encryption key object.
  *
  * @param   array  $options  Key generation options.
  *
  * @return  JCryptKey
  *
  * @since   12.1
  * @throws  InvalidArgumentException
  */
 public function generateKey(array $options = array())
 {
     // Create the new encryption key object.
     $key = new JCryptKey($this->keyType);
     // Generate an initialisation vector based on the algorithm.
     $key->public = mcrypt_create_iv(mcrypt_get_iv_size($this->type, $this->mode));
     // Get the salt and password setup.
     $salt = isset($options['salt']) ? $options['salt'] : substr(pack("h*", md5(JCrypt::genRandomBytes())), 0, 16);
     if (!isset($options['password'])) {
         throw new InvalidArgumentException('Password is not set.');
     }
     // Generate the derived key.
     $key->private = $this->pbkdf2($options['password'], $salt, mcrypt_get_key_size($this->type, $this->mode));
     return $key;
 }
开发者ID:deenison,项目名称:joomla-cms,代码行数:25,代码来源:mcrypt.php

示例5: getSalt

 /**
  * Generates a salt of specified length. The salt consists of characters in the set [./0-9A-Za-z].
  *
  * @param   integer  $length  The number of characters to return.
  *
  * @return  string  The string of random characters.
  *
  * @since   12.2
  */
 protected function getSalt($length)
 {
     $bytes = ceil($length * 6 / 8);
     $randomData = str_replace('+', '.', base64_encode(JCrypt::genRandomBytes($bytes)));
     return substr($randomData, 0, $length);
 }
开发者ID:Alibek,项目名称:joomla-platform-namespace-example,代码行数:15,代码来源:Simple.php

示例6: generate

 public function generate(&$pack, &$order, $quantity, &$serials)
 {
     if (!isset($pack->pointsgen)) {
         return;
     }
     parent::pluginParams($pack->pointsgen);
     if (empty($this->plugin_params->format) || !preg_match_all('#\\\\[|\\\\]|\\[[^]]+\\]\\{.*\\}|\\[.*\\]|.#iU', $this->plugin_params->format, $matches)) {
         $matches = array(array('[a-zA-Z0-9]{size}'));
     }
     $config = hikaserial::config();
     $fastRandom = (int) $config->get('use_fast_random', 0);
     for ($q = 0; $q < $quantity; $q++) {
         $serial = '';
         $serialObj = new stdClass();
         if (!HIKASHOP_J16 || $fastRandom) {
             $stat = @stat(__FILE__);
             if (empty($stat) || !is_array($stat)) {
                 $stat = array(php_uname());
             }
             mt_srand(crc32(microtime() . implode('|', $stat)));
         } else {
             if (empty($this->plugin_params->size) || $this->plugin_params->size == 0) {
                 $this->plugin_params->size = 15;
             }
             $rndCpt = 1;
             $random = JCrypt::genRandomBytes($this->plugin_params->size + 1);
             $shift = ord($random[0]);
         }
         foreach ($matches[0] as $m) {
             if (strlen($m) == 1) {
                 $serial .= $m;
             } else {
                 $repeat = 1;
                 $format = $m;
                 if (strpos($m, '{') !== false) {
                     list($format, $repeat) = explode('{', $m);
                     $repeat = trim(trim($repeat, '}'));
                     if (empty($repeat) || (int) $repeat == 0) {
                         $repeat = $this->plugin_params->size;
                     } else {
                         $repeat = (int) $repeat;
                     }
                 }
                 $format = substr($format, 1, -1);
                 $list = '';
                 $l = strlen($format);
                 for ($i = 0; $i < $l; $i++) {
                     if ($i + 2 < $l) {
                         if ($format[$i + 1] == '-') {
                             $s = $format[$i];
                             $e = $format[$i + 2];
                             $s1 = $s >= 'a' && $s <= 'z';
                             $s2 = $s >= 'A' && $s <= 'Z';
                             $s3 = $s >= '0' && $s <= '9';
                             $e1 = $e >= 'a' && $e <= 'z';
                             $e2 = $e >= 'A' && $e <= 'Z';
                             $e3 = $e >= '0' && $e <= '9';
                             if (!$s1 && !$s2 && !$s3) {
                                 $list .= $s . '-';
                                 $i++;
                                 // Skip '-'
                                 continue;
                             }
                             if ($s1 && $e1 || $s2 && $e2 || $s3 && $e3) {
                                 if ($s > $e) {
                                     $c = $s;
                                     $s = $e;
                                     $e = $c;
                                 }
                                 for ($c = $s; $c < $e; $c++) {
                                     $list .= $c;
                                 }
                                 $i += 2;
                             } else {
                                 if ($s1 && $e2) {
                                     for ($c = $s; $c < 'z'; $c++) {
                                         $list .= $c;
                                     }
                                     for ($c = 'A'; $c < $e; $c++) {
                                         $list .= $c;
                                     }
                                     $i += 2;
                                 } else {
                                     $list .= $s . '-';
                                     $i++;
                                     // Skip '-'
                                 }
                             }
                         } else {
                             $list .= $format[$i];
                         }
                     } else {
                         $list .= $format[$i];
                     }
                 }
                 $base = strlen($list);
                 if (!HIKASHOP_J16 || $fastRandom) {
                     for ($i = 1; $i <= $repeat; $i++) {
                         $serial .= $list[mt_rand(0, $base - 1)];
                     }
//.........这里部分代码省略.........
开发者ID:q0821,项目名称:esportshop,代码行数:101,代码来源:pointsgen.php

示例7: generateNonce

 /**
  * Method used to generate the current nonce.
  *
  * @return  string  The current nonce.
  *
  * @since   13.1
  */
 public static function generateNonce()
 {
     $mt = microtime();
     $rand = JCrypt::genRandomBytes();
     // The md5s look nicer than numbers.
     return md5($mt . $rand);
 }
开发者ID:01J,项目名称:topm,代码行数:14,代码来源:client.php

示例8: generateOteps

 /**
  * Generates a set of One Time Emergency Passwords (OTEPs) for a user. Technique taken from Joomla
  *
  * @since	1.3
  * @access	public
  * @param	string
  * @return
  */
 public static function generateOteps($otpConfig, $count = 10)
 {
     // Initialise
     $oteps = array();
     // If two factor authentication is not enabled, abort
     if (empty($otpConfig->method) || $otpConfig->method == 'none') {
         return $oteps;
     }
     $salt = "0123456789";
     $base = strlen($salt);
     $length = 16;
     for ($i = 0; $i < $count; $i++) {
         $makepass = '';
         $random = JCrypt::genRandomBytes($length + 1);
         $shift = ord($random[0]);
         for ($j = 1; $j <= $length; ++$j) {
             $makepass .= $salt[($shift + ord($random[$j])) % $base];
             $shift += ord($random[$j]);
         }
         $oteps[] = $makepass;
     }
     return $oteps;
 }
开发者ID:knigherrant,项目名称:decopatio,代码行数:31,代码来源:helper.php

示例9: hash

 /**
  * Return a random 32 byte hash value.
  * @param string extra entropy data
  */
 static function hash($length = 32)
 {
     require_once MODPATH . "gallery/vendor/joomla/crypt.php";
     return md5(JCrypt::genRandomBytes($length));
 }
开发者ID:JasonWiki,项目名称:docs,代码行数:9,代码来源:random.php

示例10: generateKey

 /**
  * Method to generate a new encryption key[/pair] object.
  *
  * @param   array  $options  Key generation options.
  *
  * @return  JCryptKey
  *
  * @since   12.1
  */
 public function generateKey(array $options = array())
 {
     // Create the new encryption key[/pair] object.
     $key = new JCryptKey('simple');
     // Just a random key of a given length.
     $key->private = JCrypt::genRandomBytes(256);
     $key->public = $key->private;
     return $key;
 }
开发者ID:01J,项目名称:skazkipronebo,代码行数:18,代码来源:simple.php

示例11: generate

 public function generate(&$pack, &$order, $quantity, &$serials)
 {
     if (!isset($pack->randomgen)) {
         return;
     }
     parent::pluginParams($pack->randomgen);
     if (empty($this->plugin_params->format) || !preg_match_all('#\\\\[|\\\\]|\\[[^]]+\\]\\{.*\\}|\\[.*\\]|.#iU', $this->plugin_params->format, $matches)) {
         $matches = array(array('[a-zA-Z0-9]{size}'));
     }
     $config = hikaserial::config();
     $fastRandom = (int) $config->get('use_fast_random', 0);
     for ($q = 0; $q < $quantity; $q++) {
         $serial = '';
         if (!HIKASHOP_J16 || $fastRandom) {
             $stat = @stat(__FILE__);
             if (empty($stat) || !is_array($stat)) {
                 $stat = array(php_uname());
             }
             mt_srand(crc32(microtime() . implode('|', $stat)));
         } else {
             if (empty($this->plugin_params->size) || $this->plugin_params->size == 0) {
                 $this->plugin_params->size = 15;
             }
             $rndCpt = 1;
             $random = JCrypt::genRandomBytes($this->plugin_params->size + 1);
             $shift = ord($random[0]);
         }
         foreach ($matches[0] as $m) {
             if (strlen($m) == 1) {
                 $serial .= $m;
             } else {
                 $repeat = 1;
                 $format = $m;
                 if (strpos($m, '{') !== false) {
                     list($format, $repeat) = explode('{', $m);
                     $repeat = trim(trim($repeat, '}'));
                     if (empty($repeat) || (int) $repeat == 0) {
                         $repeat = $this->plugin_params->size;
                     } else {
                         $repeat = (int) $repeat;
                     }
                 }
                 $format = substr($format, 1, -1);
                 $list = '';
                 $l = strlen($format);
                 for ($i = 0; $i < $l; $i++) {
                     if ($i + 2 < $l) {
                         if ($format[$i + 1] == '-') {
                             $s = $format[$i];
                             $e = $format[$i + 2];
                             $s1 = $s >= 'a' && $s <= 'z';
                             $s2 = $s >= 'A' && $s <= 'Z';
                             $s3 = $s >= '0' && $s <= '9';
                             $e1 = $e >= 'a' && $e <= 'z';
                             $e2 = $e >= 'A' && $e <= 'Z';
                             $e3 = $e >= '0' && $e <= '9';
                             if (!$s1 && !$s2 && !$s3) {
                                 $list .= $s . '-';
                                 $i++;
                                 // Skip '-'
                                 continue;
                             }
                             if ($s1 && $e1 || $s2 && $e2 || $s3 && $e3) {
                                 if ($s > $e) {
                                     $c = $s;
                                     $s = $e;
                                     $e = $c;
                                 }
                                 for ($c = $s; $c < $e; $c++) {
                                     $list .= $c;
                                 }
                                 $i += 2;
                             } else {
                                 if ($s1 && $e2) {
                                     for ($c = $s; $c < 'z'; $c++) {
                                         $list .= $c;
                                     }
                                     for ($c = 'A'; $c < $e; $c++) {
                                         $list .= $c;
                                     }
                                     $i += 2;
                                 } else {
                                     $list .= $s . '-';
                                     $i++;
                                     // Skip '-'
                                 }
                             }
                         } else {
                             $list .= $format[$i];
                         }
                     } else {
                         $list .= $format[$i];
                     }
                 }
                 $base = strlen($list);
                 if (!HIKASHOP_J16 || $fastRandom) {
                     for ($i = 1; $i <= $repeat; $i++) {
                         $serial .= $list[mt_rand(0, $base - 1)];
                     }
                 } else {
//.........这里部分代码省略.........
开发者ID:q0821,项目名称:esportshop,代码行数:101,代码来源:randomgen.php

示例12: generateRandomStringFromRange

 /**
  * Method to generate a random string from a certain range of characters
  *
  * @param   int     $length  Length of the required string
  * @param   string  $range   Characters containing the range
  *
  * @return array
  */
 protected function generateRandomStringFromRange($length, $range)
 {
     $base = strlen($range);
     $randomChars = array();
     $random = JCrypt::genRandomBytes($length + 1);
     $shift = ord($random[0]);
     for ($i = 1; $i <= $length; ++$i) {
         $randomChars[] = $range[($shift + ord($random[$i])) % $base];
         $shift += ord($random[$i]);
     }
     return $randomChars;
 }
开发者ID:pjasmits,项目名称:JoomlaPluginsBook,代码行数:20,代码来源:example.php

示例13: isOwner

 /**
  * Method to determine if script owns the path.
  *
  * @param   string  $path  Path to check ownership.
  *
  * @return  boolean  True if the php script owns the path passed.
  *
  * @since   11.1
  */
 public static function isOwner($path)
 {
     jimport('joomla.filesystem.file');
     $tmp = md5(JCrypt::genRandomBytes());
     $ssp = ini_get('session.save_path');
     $jtp = JPATH_SITE . '/tmp';
     // Try to find a writable directory
     $dir = false;
     foreach (array($jtp, $ssp, '/tmp') as $currentDir) {
         if (is_writable($currentDir)) {
             $dir = $currentDir;
             break;
         }
     }
     if ($dir) {
         $fileObject = new JFilesystemWrapperFile();
         $test = $dir . '/' . $tmp;
         // Create the test file
         $blank = '';
         $fileObject->write($test, $blank, false);
         // Test ownership
         $return = fileowner($test) == fileowner($path);
         // Delete the test file
         $fileObject->delete($test);
         return $return;
     }
     return false;
 }
开发者ID:adjaika,项目名称:J3Base,代码行数:37,代码来源:path.php

示例14: generate

 public function generate(&$pack, &$order, $quantity, &$serials)
 {
     if (!isset($pack->coupongen)) {
         return;
     }
     parent::pluginParams($pack->coupongen);
     if (empty($this->plugin_params->format) || !preg_match_all('#\\\\[|\\\\]|\\[[^]]+\\]\\{.*\\}|\\[.*\\]|.#iU', $this->plugin_params->format, $matches)) {
         $matches = array(array('[a-zA-Z0-9]{size}'));
     }
     $config = hikaserial::config();
     $fastRandom = (int) $config->get('use_fast_random', 0);
     for ($q = 0; $q < $quantity; $q++) {
         $serial = '';
         $serialObj = new stdClass();
         if (!HIKASHOP_J16 || $fastRandom) {
             $stat = @stat(__FILE__);
             if (empty($stat) || !is_array($stat)) {
                 $stat = array(php_uname());
             }
             mt_srand(crc32(microtime() . implode('|', $stat)));
         } else {
             if (empty($this->plugin_params->size) || $this->plugin_params->size == 0) {
                 $this->plugin_params->size = 15;
             }
             $rndCpt = 1;
             $random = JCrypt::genRandomBytes($this->plugin_params->size + 1);
             $shift = ord($random[0]);
         }
         foreach ($matches[0] as $m) {
             if (strlen($m) == 1) {
                 $serial .= $m;
             } else {
                 $repeat = 1;
                 $format = $m;
                 if (strpos($m, '{') !== false) {
                     list($format, $repeat) = explode('{', $m);
                     $repeat = trim(trim($repeat, '}'));
                     if (empty($repeat) || (int) $repeat == 0) {
                         $repeat = $this->plugin_params->size;
                     } else {
                         $repeat = (int) $repeat;
                     }
                 }
                 $format = substr($format, 1, -1);
                 $list = '';
                 $l = strlen($format);
                 for ($i = 0; $i < $l; $i++) {
                     if ($i + 2 < $l) {
                         if ($format[$i + 1] == '-') {
                             $s = $format[$i];
                             $e = $format[$i + 2];
                             $s1 = $s >= 'a' && $s <= 'z';
                             $s2 = $s >= 'A' && $s <= 'Z';
                             $s3 = $s >= '0' && $s <= '9';
                             $e1 = $e >= 'a' && $e <= 'z';
                             $e2 = $e >= 'A' && $e <= 'Z';
                             $e3 = $e >= '0' && $e <= '9';
                             if (!$s1 && !$s2 && !$s3) {
                                 $list .= $s . '-';
                                 $i++;
                                 // Skip '-'
                                 continue;
                             }
                             if ($s1 && $e1 || $s2 && $e2 || $s3 && $e3) {
                                 if ($s > $e) {
                                     $c = $s;
                                     $s = $e;
                                     $e = $c;
                                 }
                                 for ($c = $s; $c < $e; $c++) {
                                     $list .= $c;
                                 }
                                 $i += 2;
                             } else {
                                 if ($s1 && $e2) {
                                     for ($c = $s; $c < 'z'; $c++) {
                                         $list .= $c;
                                     }
                                     for ($c = 'A'; $c < $e; $c++) {
                                         $list .= $c;
                                     }
                                     $i += 2;
                                 } else {
                                     $list .= $s . '-';
                                     $i++;
                                     // Skip '-'
                                 }
                             }
                         } else {
                             $list .= $format[$i];
                         }
                     } else {
                         $list .= $format[$i];
                     }
                 }
                 $base = strlen($list);
                 if (!HIKASHOP_J16 || $fastRandom) {
                     for ($i = 1; $i <= $repeat; $i++) {
                         $serial .= $list[mt_rand(0, $base - 1)];
                     }
//.........这里部分代码省略.........
开发者ID:q0821,项目名称:esportshop,代码行数:101,代码来源:coupongen.php

示例15: generateOteps

 /**
  * Generates a new set of One Time Emergency Passwords (OTEPs) for a given user.
  *
  * @param   integer  $user_id  The user ID
  * @param   integer  $count    How many OTEPs to generate? Default: 10
  *
  * @return  array  The generated OTEPs
  *
  * @since   3.2
  */
 public function generateOteps($user_id, $count = 10)
 {
     $user_id = !empty($user_id) ? $user_id : (int) $this->getState('user.id');
     // Initialise
     $oteps = array();
     // Get the OTP configuration for the user
     $otpConfig = $this->getOtpConfig($user_id);
     // If two factor authentication is not enabled, abort
     if (empty($otpConfig->method) || $otpConfig->method == 'none') {
         return $oteps;
     }
     $salt = "0123456789";
     $base = strlen($salt);
     $length = 16;
     for ($i = 0; $i < $count; $i++) {
         $makepass = '';
         $random = JCrypt::genRandomBytes($length + 1);
         $shift = ord($random[0]);
         for ($j = 1; $j <= $length; ++$j) {
             $makepass .= $salt[($shift + ord($random[$j])) % $base];
             $shift += ord($random[$j]);
         }
         $oteps[] = $makepass;
     }
     $otpConfig->otep = $oteps;
     // Save the now modified OTP configuration
     $this->setOtpConfig($user_id, $otpConfig);
     return $oteps;
 }
开发者ID:Caojunkai,项目名称:working,代码行数:39,代码来源:user.php


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