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
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]
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.