Doh! Nm.
_____________________________________________
From: Duffy, Scott E
Sent: Friday, January 13, 2006 11:47 AM
To: '[email protected]'
Subject: mcrypt
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