You are here: Re: [PHP] mcrypt « PHP « IT news, forums, messages
Re: [PHP] mcrypt

Posted by Jason Gerfen on 01/13/06 20:07

Duffy, Scott E wrote:

>Trying to encrypt then decrypt text with php using mcrypt. The encrypt seems to work but when I decrypt it with a different script I get most of it but some garbage. Using blowfish. So to test.
>Encrypt.php
> $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
> $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
> $key = "This is a very secret key";
> $text = "Meet me at 11 o'clock behind the monument.";
> //echo strlen($text) . "\n";
>
> $crypttext = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $text, MCRYPT_MODE_ECB, $iv);
> echo $crypttext. "\n";
>
>decrypt.php
>
> $server = $_SERVER['SERVER_NAME'];
> $url = 'http://'.$server.'/encrypt.php';
> $fh = fopen($url,'r') or die ("cant open: $php_errormsg");
> $new_string="";
>while (! feof($fh))
>{
>$new_string = $new_string.rtrim(fgets($fh,4096));
>}
>
>$enc=$newstring;
> $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
>$enc=$_POST['text'];
>$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
>$key = "This is a very secret key";
>$text = "Meet me at 11 o'clock behind the monument.";
>//echo strlen($text) . "<br>";
>
>$crypttext = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $enc, MCRYPT_MODE_ECB, $iv);
>echo "$crypttext<br>";
>
>
>I get from decrypt
>Meet me at 11 o'clock behind the monumen3ýÚ·nÃt<br>
>Is it doing some padding or something? When I encrypt/decrypt same script it works fine.
>Maybe something to do with these?
> $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
> $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
>
>
>
>Thanks,
>
>Scott Duffy
>
>
>
Look at trim(). And your right it does have to do with using ECB.

--
Jason Gerfen

"The charge that he had insulted Turkey's armed forces was dropped, but he still faces the charge that he insulted "Turkishness", lawyers said."
~ BBC News Article

 

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

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