mcrypt installation
Results 1 to 5 of 5

Thread: mcrypt installation

  1. #1
    Member
    Join Date
    Jul 2003
    Posts
    69

    mcrypt installation

    I'm having a very difficult time getting mcrypt to work. I had trouble compiling the libraries but got them to go with a slightly older version. Here's what i've got:

    PHP 4.2.3
    libmcrypt 2.2.7 originally, got it up to 2.4.22 now
    mcrypt 2.2.6

    Using the phpinfo(), i can see that php was configured successfully with the "'--with-mcrypt=/usr/local/lib'" command and Mcrypt shows as supported and enabled with version 2.2.x; however, anytime i use the functions i get "underfined function".

    At first compiling the libraries didn't create a mcrypt.so file, but i was able to compile one from the source and put it in /usr/local/lib but to no avail.

    I'm out of ideas and having encryption is critical.

    Any help would be greatly appreciated.

    Thanks in advance!

    [EDIT]
    I had extension = mcrypt.so in the php.ini file and kept getting errors in the log file reading:

    PHP Warning: Function registration failed - duplicate name - mcrypt_ecb in Unknown on line 0

    I googled the error and found that mcrypt.so might be loaded from another ini file which in turn is loaded in php.ini. I haven't found another ini file, but i removed "extension = mcrypt.so" from my php.ini file and errors stopped in my log file. I then checked the extension with extension_loaded('mcrypt'); and it still appears to be loading, but not working
    Last edited by remnant; 10-11-2005 at 12:58 PM.

  2. #2
    Senior Member toplay's Avatar
    Join Date
    Dec 2003
    Location
    California, USA
    Posts
    597
    If phpinfo() says that mcrypt is enabled, then things should be fine. Perhaps you just misspelled the function name.

    Please post the exact code in question and what error(s) you're getting.

    PHP Manual 1 2 | PHP Func/Ver List | MySQL Manual | Articles 1 | Snippet Library | Tips | How to ask

    Regex/PCRE: 1 2 3 4 5 6 7 8 9 | MySQL: 1 2 3 4 5 6 7 8 9 | PHP Security: 1 2 3 4 5 | PHP Compiler: 1 2

    FAQ | PHP GUI: 1 2 | PHP Magz 2 | "Just keep coding, coding, coding..." by toplay

  3. #3
    Member
    Join Date
    Jul 2003
    Posts
    69
    Quote Originally Posted by toplay
    If phpinfo() says that mcrypt is enabled, then things should be fine. Perhaps you just misspelled the function name.

    Please post the exact code in question and what error(s) you're getting.

    Ok, here's something interesting. I just tried every mcrypt function in the manual and while most don't work, returning "Call to undefined function", a few do work.
    They are:

    - mcrypt_cbc()
    - mcrypt_cfb()
    - mcrypt_create_iv();
    - mcrypt_ecb();
    - mcrypt_get_block_size()
    - mcrypt_get_cipher_name()
    - mcrypt_get_iv_size()
    - mcrypt_get_key_size()
    - mcrypt_ofb();

    To say they work is a bit of a stretch as i haven't actually tested them, but using them without any parameters I get "wrong parameter count" which at least means they're recoginized.

    Also, when viewing the results of phpinfo(), there's only one line below the mcrypt section and that is "version 2.2.x" there's a table immediately below it for "Directive / Local Value / Master Value" but there's nothing in it. Should there be?

    The source code i was originally using was to test the module installation and determine which encryption methods and algorithms i had to work with.

    Here's that code:

    PHP Code:
    if (!extension_loaded('mcrypt')) {
        print 
    "mcrypt not loaded!";
        exit;
    }

    function 
    mcrypt_check_sanity() {
        
    $modes mcrypt_list_modes();
        
    $algorithms mcrypt_list_algorithms();

        foreach (
    $algorithms as $cipher) {
            if(
    mcrypt_module_self_test($cipher)) {
                print 
    $cipher." ok.\n";
            } else {
                print 
    $cipher." not ok.\n";
            }
            foreach (
    $modes as $mode) {
                if(
    mcrypt_test_module_mode($cipher,$mode)) {
                    
    $result "ok";
                } else {
                    
    $result "not ok";
                }
            print 
    $cipher." in mode ".$mode." ".$result."\n";
            
    mcrypt_module_close($td);
            }
        }
    }

    function 
    mcrypt_test_module_mode($module,$mode) {
        
    /* Data */
        
    $key 'this is a very long key, even too long for the cipher';
        
    $plain_text 'very important data';

        
    /* Open module, and create IV */
        
    $td mcrypt_module_open($module'',$mode'');
        
    $key substr($key0mcrypt_enc_get_key_size($td));
        
    $iv_size mcrypt_enc_get_iv_size($td);
        
    $iv mcrypt_create_iv($iv_sizeMCRYPT_RAND);

        
    /* Initialize encryption handle */
        
    if (mcrypt_generic_init($td$key$iv) != -1) {

            
    /* Encrypt data */
            
    $c_t mcrypt_generic($td$plain_text);
            
    mcrypt_generic_end($td);
            
    mcrypt_module_close($td);

            
    /* Reinitialize buffers for decryption */
            /* Open module, and create IV */
            
    $td mcrypt_module_open($module''$mode'');
            
    $key substr($key0mcrypt_enc_get_key_size($td));
            
    $iv_size mcrypt_enc_get_iv_size($td);
            
    $iv mcrypt_create_iv($iv_sizeMCRYPT_RAND);

            
    mcrypt_generic_init($td$key$iv);
            
    $p_t mdecrypt_generic($td$c_t);

            
    /* Clean up */
            
    mcrypt_generic_end($td);
            
    mcrypt_module_close($td);
        }

        if (
    strncmp($p_t$plain_textstrlen($plain_text)) == 0) {
            return 
    TRUE;
        } else {
            return 
    FALSE;
        }
    }

    mcrypt_check_sanity(); 
    I get the following error:
    Fatal error: Call to undefined function: mcrypt_list_modes()

  4. #4
    Senior Member toplay's Avatar
    Join Date
    Dec 2003
    Location
    California, USA
    Posts
    597
    Quote Originally Posted by remnant
    Also, when viewing the results of phpinfo(), there's only one line below the mcrypt section and that is "version 2.2.x" there's a table immediately below it for "Directive / Local Value / Master Value" but there's nothing in it. Should there be?
    No, there doesn't need to be a value for those, however, after the enabled line there should be a line for "Supported ciphers" and "Supported modes".

    Here's an example of what you're supposed to see:

    http://clust01.powweb.com/phpinfo.php#module_mcrypt

    FYI:
    http://www.phpbuilder.com/board/show...oto=nextoldest

    http://www.phpmag.net/itr/online_art...odeid,114.html

    Maybe google it for getting help:
    http://www.google.com/search?complet...=Google+Search

    Good luck.

    hth.
    PHP Manual 1 2 | PHP Func/Ver List | MySQL Manual | Articles 1 | Snippet Library | Tips | How to ask

    Regex/PCRE: 1 2 3 4 5 6 7 8 9 | MySQL: 1 2 3 4 5 6 7 8 9 | PHP Security: 1 2 3 4 5 | PHP Compiler: 1 2

    FAQ | PHP GUI: 1 2 | PHP Magz 2 | "Just keep coding, coding, coding..." by toplay

  5. #5
    Member
    Join Date
    Jul 2003
    Posts
    69
    Thanks for all your help. I've googled around a bit and it looks like 2.2.x may not support many of those functions. I'll have to see about get > 2.4.x

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •