0

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))); 
    }
1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by fsjal
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.