?
Solved

AES_ENCRYPT and AES_DECRYPT

Posted on 2014-12-01
3
Medium Priority
?
119 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Chris earned 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 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