Solved

AES_ENCRYPT and AES_DECRYPT

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

763 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