Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to figure out how to create the best secure password for AES_ENCRYPT. Specifically, how long should the password be, and how it translates into the 128 bit key length that AES typically uses.

share|improve this question
Are you planning to use AES_ENCRYPT to encrypt and then store account or user passwords? – Nick Chammas Sep 20 '11 at 3:22
Well, actually no. Passwords I would store in a one-way encryption with good salt and multiple steps. Other sensitive information requires two-way encryption, I was advised to use AES_ENCRYPT, but I instead plan to AES encrypt before sending to MySQL. But I still have that question,, if AES key length is 128 bits,, how is the password converted to the AES key? – George Bailey Sep 20 '11 at 12:39

This really isn't a mysql question, more of a "how does encryption work" question. If you have some time to kill you might want to watch this series

Here's what I felt was a good explaination of password strength I came across a while back

Remember though, the theoretical security of your password is moot if it's stored in source code that is not secure (world readable, ending up in a .mysql_history when working from the commandline, etc).

share|improve this answer
Actually, it is not "how does encryption work". Unless I am mistaken, AES encryption would encrypt with a 128 bit (16 byte) key. My question was, how is it that MySQL (and perhaps other databases) convert the password to the 128bit key. – George Bailey Sep 20 '11 at 12:44
This question can be tagged a MySQL question. In fact, there is an AES_ENCRYPT function (…) in the MySQL Documentation. There is also AES_DECRYPT. – RolandoMySQLDBA Sep 21 '11 at 20:14
up vote 1 down vote accepted

It seems someone else has already found the answer on

Sorry but I found that later from RubyForum

"The algorithm just creates a 16 byte buffer set to all zero, then loops through all the characters of the string you provide and does an assignment with bitwise OR between the two values. If we iterate until we hit the end of the 16 byte buffer, we just start over from the beginning doing ^=. For strings shorter than 16 characters, we stop at the end of the string."

share|improve this answer
+1 for finding your answer, and a good one at that !!! – RolandoMySQLDBA Sep 21 '11 at 20:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.