I have two functions, one for encrypting a string, and another for decrypting.
This is using the mcrypt() functions
I can encrypt just fine, but the decryption function (decipher()) just returns a string that looks like another decrypted string, and yet is different form the origional encrypted string...
I followed all the examples for this function, but this still isn't working.
All code is identical, whenere necessary...
Someone please help me shed some light on this.
I am using the rijndael 256 bit encryption
$key = md5('************');
// function cipher()
// takes $key & $input
// $key is password lock for this cipher
// $input is the string to be converted to 256 bit AES (rijndael) encryption
// $returns encrypted data as $encrypted data
function cipher($input)
{
global $key;
$td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td));
mcrypt_generic_init($td, $key, $iv);
$encrypted_data = mcrypt_generic($td, $input);
$encrypted_data = urlencode($encrypted_data);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $encrypted_data;
}
// function decipher
// decrypts data created using cipher() function
// returns string $descypted_data
function decipher($encrypted_data)
{
global $key;
// echo "Pre Decryption: $encrypted_data<br>\n";
$td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td));
mcrypt_generic_init($td, $key, $iv);
$decrypted_data = urldecode($encrypted_data);
$decrypted_data = mdecrypt_generic($td, $decrypted_data);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $decrypted_data;
}
Any ideas on why this isn't decrypting properly?
Both use the same exact lines of code for opening the module and creating the iv, and yet i still can't decrypt...
Thanks,.
-=Lazz=-