Does anyone know what to set mysql db field sizes and type to, to retain data integrity when using AES_ENCRYPT and AES_DECRYPT, I can't find any advice in the mysql manual?

    Here's a link to the part of the MySQL documentation that discusses the details regarding AES_ENCRYPT.

    http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html

    However, let me sum it up for you as well. You will have to set the field type in MySQL to BLOB which is for binary data. As for the length of the field, here is how you calculate it:

    16 * (trim(strlen($string) / 16) + 1)

    I used PHP functions trim() and strlen() in the above example, but here is the excerpt from the MySQL documentation:

    16 * (trunc(string_length / 16) + 1)

    Hope that helps! Good luck!

      Thanks for the help, still a bit confused. Does this mean that records relating to a field that is encrypted in this way need to be a consistent length ie BLOB(32) if $string is 16 characters?

        Write a Reply...