문제

I added an item with the following SQL sentence:

INSERT INTO `db`.`users` (`name`, `pass`) VALUES ('Terry', AES_ENCRYPT('32145', '32145'))

Then the new line was added into the table, for sure.

When I tried to find this item with 'name' and 'pass',an empty set was returned. The query sentence is below:

SELECT * FROM `users` WHERE `name` ='Terry' AND `pass`= AES_ENCRYPT('32145', '32145')

Is there anything wrong with the function AES_ENCRYPT? :-(

Updates in Apr 27th, 2014:

The type of "pass" was defined as varchar(255), which turned out to be a disaster. :-(

After I modified its type as varbinary(255), everything worked.

The original problem has been solve. But, why did type varchar(255) fail in this situation?

도움이 되었습니까?

해결책

See this fiddle and the aes_encrypt documentation.

What type is your pass column? on the fiddle I defined it like:

pass varbinary(200)

Did this insert successfully:

INSERT INTO users (name, pass) VALUES ('Terry', aes_encrypt('32145', '32145'))

Then queried it like this:

select * 
from users 
where name = 'Terry' and pass = aes_encrypt('32145', '32145');

select *, aes_decrypt(pass, '32145') 
from users 
where pass = aes_encrypt('32145', '32145');

So your query should have worked.

다른 팁

SELECT * FROM users WHERE name ='Terry' AND pass= AES_DECRYPT('32145', '32145')

MySQL Reference

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top