|
Posted by laredotornado@zipmail.com on 09/26/06 21:22
Hi,
I am using PHP 4.4.3 and trying to encrypt and decrypt data. Below are
my functions. The problem is that when I run this code, different
results are printed out ...
require("util_fns.php");
$data = "wood";
$encData = encryptData($data);
$decData = decryptData($encData);
// This prints out "wood" and then "wood" with a bunch of junk
after it.
print "$data<BR>\n$decData<BR>\n";
Could someone help me correct what's wrong? Thanks, - Dave
function encryptData($p_str)
{
if (ENCRYPTION_ENABLED) {
$iv_size = mcrypt_get_iv_size(MCRYPT_XTEA,
MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$enc = mcrypt_encrypt(MCRYPT_XTEA,
ENCRYPTION_KEY, $p_str, MCRYPT_MODE_ECB, $iv);
return $enc;
} else {
return $p_str;
} // if
} // encryptData
function decryptData($p_str)
{
if (ENCRYPTION_ENABLED) {
$iv_size = mcrypt_get_iv_size(MCRYPT_XTEA,
MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypttext = mcrypt_decrypt(MCRYPT_XTEA,
ENCRYPTION_KEY, $p_str, MCRYPT_MODE_ECB, $iv);
return $crypttext;
} else {
return $p_str;
} // if
} // decryptData
[Back to original message]
|