Can someone tell me why these two yield totally different results ?

$key = 'abcdefgh';

echo encrypt('hello');

    function encrypt($text) 
    { 
        $text = pkcs5_pad($text, mcrypt_get_block_size('rijndael-128', 'ecb'));
        return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_ECB))); 
    }

VS.

echo encrypt('hello');

    function encrypt($text) 
    { 
        $text = pkcs5_pad($text, mcrypt_get_block_size('rijndael-128', 'ecb'));
        return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, 'abcdefgh', $text, MCRYPT_MODE_ECB))); 
    }

I figured it was the same thing, but they return totally different results. However, if I pass in a constant for the same value... it yields the same result at the 2nd code snippet.

define(SALT, 'abcdefgh');
echo encrypt('hello');

    function encrypt($text) 
    { 
        $text = pkcs5_pad($text, mcrypt_get_block_size('rijndael-128', 'ecb'));
        return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, SALT, $text, MCRYPT_MODE_ECB))); 
    }

Nevermind on this one. I was stupid. Globals. Duh.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.