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_f ns.php");
$data = "wood";
$encData = encryptData($da ta);
$decData = decryptData($en cData);
// This prints out "wood" and then "wood" with a bunch of junk
after it.
print "$data<BR>\n$de cData<BR>\n";
Could someone help me correct what's wrong? Thanks, - Dave
function encryptData($p_ str)
{
if (ENCRYPTION_ENA BLED) {
$iv_size = mcrypt_get_iv_s ize(MCRYPT_XTEA ,
MCRYPT_MODE_ECB );
$iv = mcrypt_create_i v($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_ENA BLED) {
$iv_size = mcrypt_get_iv_s ize(MCRYPT_XTEA ,
MCRYPT_MODE_ECB );
$iv = mcrypt_create_i v($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
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_f ns.php");
$data = "wood";
$encData = encryptData($da ta);
$decData = decryptData($en cData);
// This prints out "wood" and then "wood" with a bunch of junk
after it.
print "$data<BR>\n$de cData<BR>\n";
Could someone help me correct what's wrong? Thanks, - Dave
function encryptData($p_ str)
{
if (ENCRYPTION_ENA BLED) {
$iv_size = mcrypt_get_iv_s ize(MCRYPT_XTEA ,
MCRYPT_MODE_ECB );
$iv = mcrypt_create_i v($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_ENA BLED) {
$iv_size = mcrypt_get_iv_s ize(MCRYPT_XTEA ,
MCRYPT_MODE_ECB );
$iv = mcrypt_create_i v($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
Comment