Page 1 of 1

Using php, mysql and mcrypt together

Posted: Sun Sep 10, 2006 5:51 pm
by the_brad
I'm having this problem:

Code: Select all

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‡ÅÜÒVSkã'4÷‹O2 zW ,u^Üê[', '\”$«5Þ{' at line 2
When I'm trying to use this statement:

Code: Select all

$entry_sql = "INSERT INTO Users (login) VALUES(' " . encrypt($_POST[Username]) . " ')";
Where the encryption function looks like:

Code: Select all

function encrypt($string)
{
	global $master_key;
	
	$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
	$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
	
	return mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $master_key, $string, MCRYPT_MODE_ECB, $iv);

}//encrypt
I'm totally new to the mcrypt library and truly have no idea why I am receiving this error, but I believe it may have something to do with the encryption function returning quotation marks in the returned string.

Any help would be much appreciated.

Thanks

Posted: Sun Sep 10, 2006 7:36 pm
by Ambush Commander

Posted: Mon Sep 11, 2006 8:29 pm
by the_brad
That worked to get the encrypted data into the db, but now when I retrieve the data and decrypt it with this function

Code: Select all

function decrypt($string)
{
	global $master_key;
	
	$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
	$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);

	return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $master_key, $string, MCRYPT_MODE_ECB, $iv);
}//decrypt
It no longer works.

Thanks for the help and any additional help would be appreciated.

Posted: Fri Sep 15, 2006 12:14 am
by the_brad
any help?