【问题标题】:Codeigniter Temporary Solution for Mcrypt extensionMcrypt 扩展的 Codeigniter 临时解决方案
【发布时间】:2015-09-06 04:33:59
【问题描述】:

我的项目有一个大问题。我将项目开发成 PYROCMS,PYROCMS 开发成 Codeigniter。但 PYROCMS 需要“Mcrypt 扩展程序”。

我有服务器的 ssh 详细信息,但我无权在服务器中安装任何东西。

我需要“Mcrypt extension”的解决方案,如何在不安装或从任何地方下载的情况下工作,并在可能的情况下将其上传到项目根目录?

我需要一个像 this 这样的解决方案,可以在 laravel 中使用这个打包到工作的项目而无需安装 Mcrypt 扩展,请提供类似 PYROCMS 的任何解决方案。

今天是项目的最后一天,无论发生什么我都需要上传,否则我会失去这个项目和我的工作。请帮忙。

谢谢

【问题讨论】:

  • 您是否尝试过简单地将 laravel-mcrypt-faker 添加到您的 composer.json 中?对 lavarel 没有直接依赖关系,所以可能是这样。
  • 不,实际上我并没有尝试与 Codeigniter 集成。
  • 看起来像重复线程..供参考,您可以在这里查看:stackoverflow.com/questions/35798048/…

标签: php codeigniter pyrocms


【解决方案1】:
  1. 转到系统/库/Encrypt.php
  2. 在构造函数中,注释在页面上回显错误的行

preview code context here..

【讨论】:

    【解决方案2】:

    您可以使用自己的库覆盖默认库。你可以试试下面的代码:

    P.S.:我没有测试过这段代码:)

    创建一个文件:

    /codeigniter/application/libraries/MY_Encrypt.php

    并有以下代码开始:

    <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class MY_Encrypt extends CI_Encrypt {
    
        public function __construct()
        {
            //parent::__construct();
        }
    
        /*
        Create your custom encryption and decryption logic by
        overriding function
        */
    
    }
    

    参考: https://ellislab.com/codeigniter/user-guide/general/creating_libraries.html

    【讨论】:

    • 感谢重播但无法正常工作我无法覆盖此错误 CI_Encrypt 将 Mcrypt 代码写入 __construct() 并且我无法覆盖父类 __construct()。
    • @renishkhunt 在这种情况下不要调用父构造函数。我已经更新了代码
    • 无法正常工作,因为错误:找不到会话 cookie。
    【解决方案3】:

    这是个技巧,但在 Pyrocms 上效果很好

    基本上是 pyrocms,在下面的模块中默认使用加密库

    akshay@db-3325:/var/www/html/pyrocms/system/cms$ grep -R encrypt . | awk '!/_lang|config/'
    ./libraries/MY_Encrypt.php:     return call_user_func_array(array($this->instance, "encrypt"), func_get_args());
    ./libraries/Streams/drivers/Streams_cp.php:         // As an added measure of obsurity, we are going to encrypt the
    ./libraries/Streams/drivers/Streams_cp.php:         $CI->load->library('encrypt');
    ./libraries/Streams/drivers/Streams_cp.php:         $CI->template->append_metadata('<script type="text/javascript" language="javascript">var stream_id='.$stream->id.'; var stream_offset='.$offset.'; var streams_module="'.$CI->encrypt->encode($CI->module_details['slug']).'";
    ./modules/comments/libraries/Comments.php:      return ci()->encrypt->encode(serialize(array(
    ./modules/comments/controllers/comments.php:        $entry = unserialize($this->encrypt->decode($this->input->post('entry')));
    ./modules/files/libraries/Files.php:                // if we want to replace a file, the file name should already be encrypted, the option was true then
    ./modules/streams_core/field_types/encrypt/field.encrypt.php:class Field_encrypt
    ./modules/streams_core/field_types/encrypt/field.encrypt.php:   public $field_type_slug         = 'encrypt';
    ./modules/streams_core/field_types/encrypt/field.encrypt.php:       $this->CI->load->library('encrypt');
    ./modules/streams_core/field_types/encrypt/field.encrypt.php:       return $this->CI->encrypt->encode($input);
    ./modules/streams_core/field_types/encrypt/field.encrypt.php:       $this->CI->load->library('encrypt');
    ./modules/streams_core/field_types/encrypt/field.encrypt.php:       $out = $this->CI->encrypt->decode($input);
    ./modules/streams_core/field_types/encrypt/field.encrypt.php:       $this->CI->load->library('encrypt');
    ./modules/streams_core/field_types/encrypt/field.encrypt.php:       $options['value'] = ($_POST) ? $params['value'] : $this->CI->encrypt->decode($params['value']);
    ./modules/streams_core/controllers/ajax.php:        $this->load->library('encrypt');
    ./modules/streams_core/controllers/ajax.php:        $module = $this->encrypt->decode($module);
    

    您的解决方案很少

    1. encryption 库与openssl 一起使用,而不是encrypt 库(使用mcrypt 扩展名),在这些模块中替换它。

    2. 或下载https://raw.githubusercontent.com/bcit-ci/CodeIgniter/develop/system/libraries/Encryption.php 并放入system/codeigniter/libraries 并使用以下代码在system/cms/libraries 中创建MY_Encrypt.php,它会覆盖原始CI_Encrypt 库,用于encodedecode 我们只是调用@ 987654333@ 和 decrypt 的新加密类。

    .

    akshay@db-3325:/var/www/html/pyrocms/system/cms/libraries$ cat MY_Encrypt.php 
    <?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    
    require_once BASEPATH.'libraries/Encryption.php';
    
    class MY_Encrypt extends CI_Encrypt {
        protected $instance;
        public function __construct(){
            $this->instance = new CI_Encryption();  
        }
        public function encode($data, $params = NULL){
            return call_user_func_array(array($this->instance, "encrypt"), func_get_args());
        }
        public function decode($data,  $params = NULL){
            return call_user_func_array(array($this->instance, "decrypt"), func_get_args());
        }
    }
    

    3.或者您创建自己的函数并在之前加载

    .

    akshay@db-3325:/var/www/html/pyrocms$ pwd
    /var/www/html/pyrocms
    
    # from index.php
    
    require_once FCPATH.'compatibility.php';
    require_once BASEPATH.'core/CodeIgniter'.EXT;
    /* End of file index.php */
    

    如下所示

    <?php
    /*  File : compatibility.php
        Example : If PHP Greater than 7, then lets create these function as it depreceated 
        http://php.net/manual/en/migration71.deprecated.php
    */
    if(version_compare(PHP_VERSION,7,">"))
    {
        function mcrypt_encrypt(){
    
        }
        function mcrypt_decrypt(){
    
        }
    
        function mcrypt_encode(){
    
        }
        function mcrypt_decode(){
    
        }
    
        // Do something with these constants
    
        //MCRYPT_MODE_ECB
        //MCRYPT_MODE_CBC
        //MCRYPT_RAND
        //MCRYPT_RIJNDAEL_256
    
        function mcrypt_get_iv_size(){
    
        }
        function mcrypt_create_iv(){
    
        }
    
    
    }
    

    【讨论】:

      【解决方案4】:

      打开,system/libraries/Encrpyte.php

      转到第 47 行并更改它

              $this->_mcrypt_exists =  TRUE;
      

      转到第 290 行添加符号@

              $init_size = @mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode());
      

      转到第 299 行并添加符号 @

              return rtrim(@mcrypt_decrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), "\0");
      

      【讨论】:

        【解决方案5】:

        查看此文件以获取帮助我已从此处获取所有代码... encrypt.php 我用这个解决了这个问题。在 CI->system->libraries->encrypt.php 文件中 代替

        if (($this->_mcrypt_exists = function_exists('mcrypt_encrypt')) === FALSE)
        {
            show_error('The Encrypt library requires the Mcrypt extension.');
        }
        

        我检查了 mcrypt_encrypt 函数。

        $this->_mcrypt_exists = ( ! function_exists('mcrypt_encrypt')) ? FALSE : TRUE;
        

        并基于如下所示的编码函数中使用的函数,如下所示

        function encode($string, $key = '')
        {
            $key = $this->get_key($key);
            if ($this->_mcrypt_exists === TRUE)
            {
                $enc = $this->mcrypt_encode($string, $key);
            }
            else
            {
                $enc = $this->_xor_encode($string, $key);
            }
            return base64_encode($enc);
        } 
        

        这里是_xor_encode函数

        function _xor_encode($string, $key)
        {
            $rand = '';
            while (strlen($rand) < 32)
            {
                $rand .= mt_rand(0, mt_getrandmax());
            }
            $rand = $this->hash($rand);
            $enc = '';
            for ($i = 0; $i < strlen($string); $i++)
            {
                $enc .= substr($rand, ($i % strlen($rand)), 1).(substr($rand, ($i % strlen($rand)), 1) ^ substr($string, $i, 1));
            }
            return $this->_xor_merge($enc, $key);
        }
        

        和_xor_merge函数

        function _xor_merge($string, $key)
        {
            $hash = $this->hash($key);
            $str = '';
            for ($i = 0; $i < strlen($string); $i++)
            {
                $str .= substr($string, $i, 1) ^ substr($hash, ($i % strlen($hash)), 1);
            }
            return $str;
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-03-06
          • 2018-10-22
          • 1970-01-01
          • 2011-06-30
          • 2012-10-31
          • 2013-01-18
          相关资源
          最近更新 更多