Re: MCrypt not decrypting simple text

From: Date: Fri, 21 Mar 2008 23:13:31 +0000
Subject: Re: MCrypt not decrypting simple text
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-271958@lists.php.net to get a copy of this message
Ok, looks like I'm not getting much intrest here, can anyone recomend which newsgroup I should post this under? Is there a crypto group or anything of the like?: - Dan ""Dan"" <frozendice@gmail.com> wrote in message news:AB.E9.09437.752D2E74@pb1.pair.com...
I'm using MCrypt and I have two very simple functions. All I'm doing is giving the function some text and a password, it encrypts the text and saves it as a text file on the server. Then I at some later time run another php file which decrypts using the decrypt function given the text and the SAME password as the first time and all I get is garbage. What am I doing wrong? What do I need to change so that I can get this to work the way I described? function aes_128_encrypt($text,$password) {
      $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
       $iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
       $text .= chr(3).chr(3).chr(3);
       return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $password, $text, MCRYPT_MODE_ECB, $iv));
} // End of function and function aes_128_decrypt($encrypted_text,$password) {
       $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
       $iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
       return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $password, pack("H*", $encrypted_text), MCRYPT_MODE_ECB, $iv);
} // End of function - Dan


« previous php.general (#271958) next »