• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 820
  • Last Modified:

Can't get AES_DECRYPT to work

Am trying to decypt a string that has been successfully encrypted using AES_ENCRYPT in MySQL..

I ran ....
update table set string_encrypted= AES_ENCRYPT(string,'password')

To decrypt I've run...
select AES_DECRYPT(string_encrypted,'password') from table

but I keep on getting back NULL.... no syntax errors.

I know the encryted value is in the field and if I copy and paste the value into the query it works.
I'm using varchar but have also tried blob, binary, text and all sorts of other combinations.

Thanks for help...
0
inajam
Asked:
inajam
  • 2
  • 2
1 Solution
 
hieloCommented:
I believe you need to supply the "alias" for the unencrypted field. Try:
select AES_DECRYPT(string_encrypted,'password') AS oldString from table

oldString is the field that will contain your unencrypted data
0
 
inajamAuthor Commented:
Thanks hielo, but that doesn't seem to make any difference... still getting NULL returned.

0
 
hieloCommented:
OK, the manual says "The input arguments may be any length. If either argument is NULL, the result of this function is also NULL. Because AES is a block-level algorithm, padding is used to encode uneven length strings"

Hence, try:

select AES_DECRYPT( REPLACE(`string_encrypted`,'\0',''), 'password') AS oldString from table

If that does not work, it could be a driver issue. Refer to the following:
http://bugs.mysql.com/bug.php?id=32841
specifically, the last post.
0
 
inajamAuthor Commented:
Thanks hielo

It does look like a driver issue from my windows machine since the decrypt works when I make a query using my server side language.   I just assumed that if the query didn't work from my machine it wouldn't work at all.  
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now