You are here: Re: Mcrypt problem on PHP 4.3.1 / FreeBSD 5.3 « PHP Programming Language « IT news, forums, messages
Re: Mcrypt problem on PHP 4.3.1 / FreeBSD 5.3

Posted by sylvian stone on 11/16/56 11:29

OK,

I use the following settings:

$cipher = MCRYPT_GOST;
$mode = MCRYPT_MODE_ECB;
$rand_src = MCRYPT_RAND;

I then randomly generate a hash and assign it to variable $hash, run it
through addslashes(), and use the following to encrypt:



$handle = mcrypt_module_open ($cipher, '', $mode, '');

if (!$handle)
die ("Couldn't locate open mcrypt module.");
$ivector =
mcrypt_create_iv(mcrypt_get_iv_size($cipher,$mode),$rand_src);

if (mcrypt_generic_init ($handle, $hash, $ivector) == -1)
die ("Error: mcrypt failure.");

$address1 = addslashes(mcrypt_generic($handle,$address1));
$address2 = addslashes(mcrypt_generic($handle,$address2));
$address3 = addslashes(mcrypt_generic($handle,$address3));
$address4 = addslashes(mcrypt_generic($handle,$address4));
$address5 = addslashes(mcrypt_generic($handle,$address5));
$postcode = addslashes(mcrypt_generic($handle,$postcode));
$firstname = addslashes(mcrypt_generic($handle,$firstname));
$surname = addslashes(mcrypt_generic($handle,$surname));
$telephone = addslashes(mcrypt_generic($handle,$telephone));
$em = addslashes(mcrypt_generic($handle,$email));
$ivector = addslashes($ivector);
$username = addslashes($email);

mcrypt_generic_deinit($handle);


These are inserted into the database tables, then I later decrypt with:


$site_sql="SELECT * FROM security WHERE client_id ='$client_id' LIMIT
1";

$site_get = mysql_query($site_sql) or die (mysql_error());


while ($row = mysql_fetch_array($site_get))
{
$hash_temp = stripslashes($row['hash']);
$iv_temp = stripslashes($row['iv']);
}

$site_sql="SELECT * FROM client WHERE client_id ='$client_id' LIMIT 1";
$site_get = mysql_query($site_sql) or die (mysql_error());
while ($row = mysql_fetch_array($site_get))
{
$handle = @mcrypt_module_open ($cipher, '', $mode, '');
if (!$handle)
die ("Couldn't locate open mcrypt module.");
if (@mcrypt_generic_init ($handle, $hash_temp, $iv_temp) == -1)
die ("Error: mcrypt failure.");
$title = $row['title'];
$firstname = trim(stripslashes(@mdecrypt_generic($handle,
$row['firstname'])));
$surname = trim(stripslashes(@mdecrypt_generic($handle,
$row['surname'])));
$address1 = trim(stripslashes(@mdecrypt_generic($handle,
$row['address1'])));
$address2 = trim(stripslashes(@mdecrypt_generic($handle,
$row['address2'])));
$address3 = trim(stripslashes(@mdecrypt_generic($handle,
$row['address3'])));
$address4 = trim(stripslashes(@mdecrypt_generic($handle,
$row['address4'])));
$address5 = trim(stripslashes(@mdecrypt_generic($handle,
$row['address5'])));
$postcode = trim(stripslashes(@mdecrypt_generic($handle,
$row['postcode'])));
$telephone = trim(stripslashes(@mdecrypt_generic($handle,
$row['telephone'])));
$email = trim(stripslashes(@mdecrypt_generic($handle,
$row['email'])));
@mcrypt_generic_deinit($handle);
}

As I said, the data is decrypted fine. But this error keeps popping
up...

Very obscure....

Thanks
SS

 

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

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