Solved

AES_ENCRYPT and AES_DECRYPT

Posted on 2014-12-01
3
107 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now