|
Posted by laredotornado on 12/12/06 18:05
Hi, I'm using PHP 4.4.4. I have two functions, and my goal is to print
out "encryption/decrpytion successful".
$str = "hello";
$encryptedStr = encryptData($str);
$decryptedStr = decryptStr($encryptedStr);
if ($str == $decryptedStr) {
print "encryption/decryption successful.";
}
Unfortunately, this is not happening. These are my functions ...
function encryptData($p_str)
{
$iv = ENCRYPTION_VECTOR;
$enc = mcrypt_encrypt(MCRYPT_XTEA,
ENCRYPTION_KEY, $p_str, MCRYPT_MODE_ECB, $iv);
return $enc;
} // encryptstring
function decryptData($p_str)
{
$iv = ENCRYPTION_VECTOR;
$crypttext = mcrypt_decrypt(MCRYPT_XTEA,
ENCRYPTION_KEY, $p_str, MCRYPT_MODE_ECB, $iv);
return $crypttext;
} // decryptData
ENCRYPTION_VECTOR is a hard coded string I created with this call
$iv_size = mcrypt_get_iv_size(MCRYPT_XTEA,
MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
I cut and pasted the value of "$iv" into my ENCRYPTION_VECTOR constant.
Any idea why my functions are failing?
Thanks, - Dave
Navigation:
[Reply to this message]
|