Codeigniter Temporary Solution for Mcrypt extension

11.4k views Asked by At

i have a big problem in my project. i developed project into PYROCMS and PYROCMS developed into Codeigniter. but PYROCMS required "Mcrypt extension".

i have a ssh detail of server but i don't have permission to install anything into server.

i need a solution for "Mcrypt extension" how to working without install or Download from anywhere and upload it in project root directory if it is possible?.

i need a solution like this it is possible in laravel using this packed to working project without install Mcrypt extension please give a any solution like that for PYROCMS.

today is last day of project i need to upload today whatever happen otherwise i lose this project and also my work. please help.

Thanks

5

There are 5 answers

3
Avinash On

You can override default library with your own library. You can try below code:

P.S.: I have not tested this code :)

Create a file:

/codeigniter/application/libraries/MY_Encrypt.php

And have below code to get started:

<?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
    */

}

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

0
Akshay Hegde On

This is trick, but works fine with Pyrocms

Basically pyrocms, using encrypt library by default in below modules

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);

You got few solutions

  1. Use encryption library with openssl instead of encrypt library (which uses mcrypt extension), replace it in these modules.

  2. OR Download https://raw.githubusercontent.com/bcit-ci/CodeIgniter/develop/system/libraries/Encryption.php and place in system/codeigniter/libraries and create MY_Encrypt.php in system/cms/libraries with below code, which override original CI_Encrypt library, for encode and decode we just calling encrypt and decrypt of new encryption class.

.

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. OR you create your own function and just load before

.

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 */

which is something like below

<?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(){

    }


}
0
Turan Zamanlı On

Open, system/libraries/Encrpyte.php

goto line 47 and change that

        $this->_mcrypt_exists =  TRUE;

goto line 290 add symbol @

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

go to line 299 and add symbol @

        return rtrim(@mcrypt_decrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), "\0");
0
gondwe On
  1. goto system/libraries/Encrypt.php
  2. Inside the constructor, Comment the line echoing the error on page

preview code context here..

0
mohitesachin217 On

see this file for help I have taken all code from here ... encrypt.php I solved this problem with this.. In CI->system->libraries->encrypt.php file in place of

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

I checked for mcrypt_encrypt function .

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

and based on that used function as below in encode function as shown below

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);
} 

Here is _xor_encode function

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);
}

and _xor_merge function

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;
}