Page 1 of 1
aes_encrypt question
Posted: Mon Mar 07, 2005 7:35 pm
by sweenyman
Can anybody tell me what the
second arguement in this function is all about
Code: Select all
aes_encrypt('$password','text_key')
I seem to be getting a syntax error when I use it in an INSERT.
Section of Insert code below
Code: Select all
"e;x_address2='$cl4',"e;.
"e;x_email=aes_encrypt('$cl5','ke'),"e;.
"e;x_phone='$cl6',"e;.
Thanks
Sean
Posted: Mon Mar 07, 2005 7:37 pm
by feyd
it is the key string.. used to cipher the data. aes_decrypt uses it to decipher the ciphered data.
Posted: Mon Mar 07, 2005 7:44 pm
by sweenyman
feyd wrote:it is the key string.. used to cipher the data. aes_decrypt uses it to decipher the ciphered data.
Hi Feyd thanx for your prompt reply!!
Can it be "made up" i.e anything you like, or does it have to follow some format or syntax.
Can you figure out why my version of it might not be working. It works fine without the encryption function. Have I got the syntax right?
Sean
Posted: Mon Mar 07, 2005 7:50 pm
by feyd
what version of mysql are you using? aes_* was added in 4.0.2
Posted: Mon Mar 07, 2005 8:04 pm
by sweenyman
feyd wrote:what version of mysql are you using? aes_* was added in 4.0.2
OOOOOOOOOOOOps!!!
Looks like Im using Version 3.23.49.

Have to get updated. Thanks for you help as always
Sean
Posted: Fri Mar 11, 2005 2:52 pm
by sweenyman
sweenyman wrote:feyd wrote:what version of mysql are you using? aes_* was added in 4.0.2
OOOOOOOOOOOOps!!!
Looks like Im using Version 3.23.49.

Have to get updated. Thanks for you help as always
Sean
I've upgraded to latest MySQL now I'm trying to get my head around the AES_ENCRYPT and AES_DECRYPT sql functions
Encryption works fine see below...
INSERT INTO.....
Code: Select all
"e;x_address2='$cl4',"e;.
"e;x_email=AES_ENCRYPT('$cl5','text_key'),"e;.
"e;x_phone='$cl6',"e;.
where $cl5 is the value from a form txtbox and inserted into column x_email in DB
but decryption...
Code: Select all
$sql = "e;SELECT AES_DECRYPT('x_email','text_key') FROM clients where x_rec='58'"e; ;
dosen't work
When I run this query in phpMyAdmin program it returns NULL
The column
does contain encrypted data (gobble-de-gook).
Any ideas what's amiss.
Regards
Sean
Posted: Fri Mar 11, 2005 3:01 pm
by feyd
single quotes don't reference columns or tables, they are strings to mysql. Backticks (`) help mysql know what is a reference and what isn't.
Posted: Fri Mar 11, 2005 3:16 pm
by sweenyman
feyd wrote:single quotes don't reference columns or tables, they are strings to mysql. Backticks (`) help mysql know what is a reference and what isn't.
Hi feyd
Thanks for your reply
Done that
It still returns NULL
$sql = "SELECT AES_DECRYPT(`x_email`,'text_key') FROM `clients` where `x_rec`='58'" ;
Other than back ticks does syntax of my code look OK?
Regards
Sean
Posted: Fri Mar 11, 2005 3:22 pm
by infolock
just try this and see what you get...
Code: Select all
$sql = mysql_query("SELECT AES_DECRYPT(x_email,text_key) FROM clients where x_rec='58'") or die(MySQL_Error());
also, what type of field is x_rec? Is it a text or an integer field? if integer, remove the ' marks around 58...
also i put an error check on the end. see if that returns anything useful.
Posted: Fri Mar 11, 2005 5:40 pm
by sweenyman
infolock wrote:just try this and see what you get...
Code: Select all
$sql = mysql_query("SELECT AES_DECRYPT(x_email,text_key) FROM clients where x_rec='58'") or die(MySQL_Error());
also, what type of field is x_rec? Is it a text or an integer field? if integer, remove the ' marks around 58...
also i put an error check on the end. see if that returns anything useful.
Hi again
I can now get the desired result in myphpadmin and in the command line mysql>..
I even pasted the very php code the myphpadmin created.
Code: Select all
$sql = 'SELECT AES_DECRYPT( `x_email` , \'text_key\' )'
. ' FROM `clients` '
. ' WHERE `x_rec` =61 LIMIT 0, 30';
I now have a problen echoing the decrypted data to the web page. When I normally use.. echo $row['x_email'];This works if I dont decrypt the data but just echoes >
Posted: Fri Mar 11, 2005 5:59 pm
by Weirdan
Code: Select all
select aes_decrypt(x_email, 'text_key') as x_email from clients where.....
You would use the alias ('as x_email' part) to make it work.
Posted: Fri Mar 11, 2005 6:10 pm
by sweenyman
Weirdan wrote:Code: Select all
select aes_decrypt(x_email, 'text_key') as x_email from clients where.....
You would use the alias ('as x_email' part) to make it work.
Yahoooooooooooooo!!!!!!!
Thanks a lot Weirdan. Now I have to put all that hair back on my head that I've been pulling out all day!!
It
can be done ..cant it? ehhh....
Thanks to everyone else too!
Regards
Sean