|
Posted by Benjamin on 09/27/06 01:52
I would suggest you take a look at the mcypt functions found at
http://www.php.net/mcrypt
you need to call mcrypt_module_open first to get a module then pass it
as the first parameter for the rest of the functions. I would suggest
you look at the documentation for all the params
laredotornado@zipmail.com wrote:
> 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]
|