我发现了类似的问题,但这个问题没有明确的答案。我有这张桌子:
CREATE DATABASE testDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE TABLE testTable
(
firstName binary(32) not null,
lastName binary(32) not null
/* Other non-binary fields omitted */
)
engine=INNODB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
该语句执行得很好:
INSERT INTO testTable (firstName) VALUES (AES_ENCRYPT('Testname', 'test'));
但是,这将返回 NULL:
SELECT AES_DECRYPT(firstName, 'test') FROM testTable;
为什么这会返回 NULL?
Fwiw,这将按预期返回“testValue”:
SELECT AES_DECRYPT(AES_ENCRYPT('testValue','thekey'), 'thekey');