Jump to content

strange behaviour with aes_decrypt


trehoret

Recommended Posts

Hi,

I have some code where i am storing some passwords in the database, as a storage facility for the users.
Storing the password is fine ( aes_encrypt() ) is fine, but when i want to retrieve the password using aes_decrypt i get an error :

my query:
[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]SELECT aes_decrypt(passx, "key")FROM `tpass` [!--colorc--][/span][!--/colorc--]

Error:
[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]#1064 - 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 '( passx , "key" ) FROM `tpass` LIMIT 0, 30' at line 1 [!--colorc--][/span][!--/colorc--]

Now here is the weird thing:
I get this error using my php code or even launching the query directly in phpmyadmin BUT if i launch the query directly in MySQL command line or even through MySQL Query Browser under windows, this is fine, i get the password, so this sounds to me like a PHP problem.

Does PHP do any kind of SQL pre-validation before sending the query to the server or something ?

I am using :
PHP 4.4.0
MySQL 4.1.13
Apache 2.0.54

Thanks.
Jim

Link to comment
https://forums.phpfreaks.com/topic/9961-strange-behaviour-with-aes_decrypt/
Share on other sites

Always post the exact PHP used so people on this forum can help you easier and quicker.

Are you using the "AS" keyword? example:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] aes_decrypt(`passx`, [color=red]"key"[/color]) [color=green]AS[/color] decrypted_data [color=green]FROM[/color] [color=orange]`tpass`[/color] [!--sql2--][/div][!--sql3--]

Quick PHP example:
[code]
$sql = 'SELECT aes_decrypt(`passx`, "key") AS decrypted_data FROM `tpass`';
$result = mysql_query($sql) or die("SQL: $sql <br/>Error: " . mysql_error());
while ($row = mysql_fetch_assoc($result)) echo 'Data: ', $row['decrypted_data'], '<br/>';
[/code]
Well, post the EXACT code!

Just by going of your sql statement, you need a space before "FROM". But the error is before that.

Edit:

And tell us what type of editor you're using and double check to make sure there are no hidden characters in the query that's causing the syntax problem. This has happened to a few members. Are you on Windows or Linux?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.