AES_ENCRYPT uses a 128 bit long key to encrypt the data, but how does mysql handle longer or shorter keys? I found out that pycrypto for instances recomend to transform the key by using md5 sha1 sha2, etc hashes and then using the the resulting key for encryption. How does it work with mysql?
|
|
MySQL 5.5 does not handle other key sizes. As stated on http://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html:
I never tried to pass bigger key to MySQL, but I guess it would yield an error or truncate to 128 bits. I'm not sure if MD5 use it's full codomain because I can't find any proof of that MD5 is a surjection. So I assume that you will get As far as smaller keys are concerned, I guess that By the way, I do not understand why you just don't generate key to the given size. If you have some constraints (already existing key you want to reuse, ...) let us know. |
|||||||||
|
|
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 XOR 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."
which looks like that in Ruby
and I applied that to python:
It's probably wise not to use a repetitive password such as |
|||||||||
|
