You are here: Re: Trouble decrypting data « PHP Programming Language « IT news, forums, messages
Re: Trouble decrypting data

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация