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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php