This is a discussion on MCrypt not decrypting simple text within the PHP General forums, part of the PHP Programming Forums category; I'm using MCrypt and I have two very simple functions. All I'm doing is giving the function some ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |