Adding more to the defendant if someone is interested:
To sort the encrypted AES field,
ORDER BY LOWER(CONVERT(AES_DECRYPT(field, 'key') USING latin1))
Search inside AES encrypted field
SELECT *, AES_DECRYPT(`field`, 'key') as `decrypted` FROM enc WHERE LOWER(CONVERT(AES_DECRYPT(`field`, 'key') USING latin1)) LIKE '$input' LOWER('%" . $keyword . "%'))
This is because the AESE_DECRYPT function returns a binary string that cannot be used by LOWER
source share