I am trying to encrypt part of a mySQL-database with AES_ENCRYPT, and of course retrieve the data later on with AES_DECRYPT. But when the field contain special characters like æ, ø eller å, these come back as �
I have been trying to read up on why this is, but haven't found a solution.
First of I change the field-type to BLOB:
ALTER TABLE 'table' MODIFY field BLOB
Then I do the encryption:
UPDATE 'table' SET field = AES_ENCRYPT(field, '$key')
Everything is stored, but when trying to extract the data again:
SELECT AES_DECRYPT(field,'$key') AS variable FROM table WHERE....
all the special characters are displayed as � when echo in PHP
I think I got the UTF-8 covered, in both HTML and mySQL:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
and
mysqli_set_charset($connect,'utf8');
so storing the special characters in the mySQL-database, retrieving and displaying them with PHP works just fine as long as the field is VARCHAR and no encryption has been done. I also read about problems with the special characters in binary fields like BLOB, but I recon I'm not the first one that tries to encrypt and store an Æ or an Ø :)
Any hints would be really appreciated! Thanks!