Current location: Hot Scripts Forums » Programming Languages » PHP » AES_Encrypt / AES_DECRYPT Syntax Issue?


AES_Encrypt / AES_DECRYPT Syntax Issue?

Reply
  #1 (permalink)  
Old 09-21-05, 02:50 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
AES_Encrypt / AES_DECRYPT Syntax Issue?

Hello everyone,

I am trying to store a string into MySQL Database in encrypted format using the AES_Encrypt/AES_DECRYPT Function, that is available for MySQL version 4.0.2 and higher ( I use 4.1.x, so the version is fine). Here is my SQL Strings:

For Insert Into Database:

Code:
INSERT INTO tableName VALUES (AES_ENCRYPT('1234567891234567', 'motb6q4x79yoefbj' ));
Where 'motb6q4x79yoefbj' is an encryption key generated by random using a random string generating function.

Query to retrieve and Decrypt the string:

Code:
SELECT AES_DECRYPT(ccnum,'motb6q4x79yoefbj') FROM tableName;
As far as the MySQL Table that is being used, its a single column table with Data Type VARCHAR and length of 100 characters (for testing purposes only).

The INSERT SQL statement executes fine. However, the Query to retrieve and Decrypt the string generates the following error:

Code:
#1064 - You have an error in your SQL syntax;
Does anyone see anything wrong with the SQL Syntax being used here?
__________________
Reply With Quote
  #2 (permalink)  
Old 09-21-05, 10:43 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
I just found the answer to my question. Here is the correct syntax for the Query (in case anyone else is interested in using this):

Code:
SELECT AES_DECRYPT(ccnum, 'motb6q4x79yoefbj') AS decrypted FROM tableName;
For more information about AES_ENCRYPT/DECRYPT, you can take a look at:

http://dev.mysql.com/doc/mysql/en/en...functions.html
__________________
Reply With Quote
  #3 (permalink)  
Old 11-13-05, 06:51 AM
mayki mayki is offline
New Member
 
Join Date: Nov 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
help with encryption

Hello =)
I'm kind of new in SQL, and I'd like to know what is that ccnum parameter in AES_DECRYPT function...
Thank you wery much
majky

Quote:
SELECT AES_DECRYPT(ccnum,'motb6q4x79yoefbj') FROM tableName;
Reply With Quote
  #4 (permalink)  
Old 11-13-05, 10:13 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
The ccnum parameter is a database column that stores credit card information. In reality, the ccnum parameter can be anything you want it to be, from password to an encrypted email.

Just don't loose the key you use, because if you loose the key your original values are gone for good!
__________________
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue Tracking and Task management SlackeR Script Requests 8 10-05-05 04:29 PM
Language issue in from property, Please Help AskAR ASP 0 08-10-05 06:40 AM
MySQL Syntax error when using a variable for table name lppa2004 PHP 4 08-04-05 12:24 AM
Can't find error in sql syntax. Dr.Jamescook PHP 7 06-14-05 11:45 AM
Invalid Syntax on CSS Forum Description ub3r Hot Scripts Forum Questions, Suggestions and Feedback 0 08-31-04 09:30 PM


All times are GMT -5. The time now is 06:13 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.