Solved

AES_ENCRYPT and AES_DECRYPT

Posted on 2014-12-01
3
114 Views
Last Modified: 2014-12-11
Im trying to encrypt a password to be held in a database, however I need to know the password to authenticate against another system so need to be able to decrpyt it again.

So to encrypt the password Im using:-
INSERT INTO `suppliers`.`users` (`username`, `password`) VALUES ('user1', AES_ENCRYPT('mypassword','cryptstring'))

Open in new window


And then to decypt it Im using:-
SELECT `username`,  unhex(AES_DECRYPT(`users`.`password`,'cryptstring')) FROM `suppliers`.`users`

Open in new window


Which should work, however it returns as a decrpted password as '6d7970617373776f7264' which I initally thought was HEX representation of the password but when I try to run it through unhex it just returns null

Any ideas?
0
Comment
Question by:tonelm54
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Chris earned 500 total points
ID: 40473901
I've seen this before. IIRC MySQL was incorrectly returning binary data instead of a string. Try the below:

SELECT `username`,  CAST(AES_DECRYPT(`users`.`password`,'cryptstring') AS CHAR(60)) FROM `suppliers`.`users`
0
 
LVL 12

Expert Comment

by:Chris
ID: 40489257
Did this resolve your problem?
0
 

Author Closing Comment

by:tonelm54
ID: 40494763
Thank you
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CheckListBox usage 3 71
Count rows in a MySQL statement, but don't return the value in the results 4 40
How many transactions can mysql handle? 3 42
MySQL  on Tomcat 8 68
Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question