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


PHP Encrypt::_rand方法代码示例

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


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

示例1: encode

 public function encode($data)
 {
     // Set the rand type if it has not already been set
     if (Encrypt::$_rand === NULL) {
         $is_windows = DIRECTORY_SEPARATOR === '\\';
         if ($is_windows) {
             // Windows only supports the system random number generator
             Encrypt::$_rand = MCRYPT_RAND;
         } else {
             if (defined('MCRYPT_DEV_URANDOM')) {
                 // Use /dev/urandom
                 Encrypt::$_rand = MCRYPT_DEV_URANDOM;
             } elseif (defined('MCRYPT_DEV_RANDOM')) {
                 // Use /dev/random
                 Encrypt::$_rand = MCRYPT_DEV_RANDOM;
             } else {
                 // Use the system random number generator
                 Encrypt::$_rand = MCRYPT_RAND;
             }
         }
     }
     if (Encrypt::$_rand === MCRYPT_RAND) {
         // The system random number generator must always be seeded each
         // time it is used, or it will not produce true random results
         mt_srand();
     }
     // Create a random initialization vector of the proper size for the current cipher
     $iv = mcrypt_create_iv($this->_iv_size, Encrypt::$_rand);
     // Encrypt the data using the configured options and generated iv
     $data = mcrypt_encrypt($this->_cipher, $this->_key, $data, $this->_mode, $iv);
     // Use base64 encoding to convert to a string
     return base64_encode($iv . $data);
 }
开发者ID:noikiy,项目名称:kohana,代码行数:33,代码来源:Encrypt.php

示例2: _create_iv

 /**
  * Proxy for the mcrypt_create_iv function - to allow mocking and testing against KAT vectors
  *
  * @return string the initialization vector or FALSE on error
  */
 protected function _create_iv()
 {
     /*
      * Silently use MCRYPT_DEV_URANDOM when the chosen random number generator
      * is not one of those that are considered secure.
      *
      * Also sets Encrypt::$_rand to MCRYPT_DEV_URANDOM when it's not already set
      */
     if (Encrypt::$_rand !== MCRYPT_DEV_URANDOM and Encrypt::$_rand !== MCRYPT_DEV_RANDOM) {
         Encrypt::$_rand = MCRYPT_DEV_URANDOM;
     }
     // Create a random initialization vector of the proper size for the current cipher
     return mcrypt_create_iv($this->_iv_size, Encrypt::$_rand);
 }
开发者ID:robert-kampas,项目名称:games-collection-manager,代码行数:19,代码来源:Encrypt.php


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