Jump to content


Photo

strange behaviour with aes_decrypt


  • Please log in to reply
3 replies to this topic

#1 trehoret

trehoret
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 May 2006 - 12:01 AM

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



#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 19 May 2006 - 12:34 AM

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`, "key") AS decrypted_data FROM `tpass` [!--sql2--][/div][!--sql3--]

Quick PHP example:
$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/>';


#3 trehoret

trehoret
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 May 2006 - 01:57 AM

Yes I have tried using "As" but no luck either through php.

#4 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 19 May 2006 - 02:07 AM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users