encryption - How to use AES_ENCRYPT and AES_DECRYPT in mysql -
i created user table
create table `user` ( `id` bigint unsigned not null auto_increment , `first_name` varbinary(100) null , `address` varbinary(200) not null , primary key (`id`)) engine = innodb default character set = utf8 collate = utf8_general_ci;
i inserted 1 row:
insert user (first_name, address) values (aes_encrypt('obama', 'usa2010'),aes_encrypt('obama', 'usa2010'));
to select row used:
select aes_decrypt(first_name, 'usa2010'), aes_decrypt(address, 'usa2010') user;
i getting following result.what need see data.no data visible me.
according manual:
aes_encrypt() encrypts string , returns binary string. aes_decrypt() decrypts encrypted string , returns original string.
i don't know why still returning binary string in case. anyway, try this:
select *, cast(aes_decrypt(first_name, 'usa2010') char(50)) first_name_decrypt user
and use first_name_decrypt
instead of first_name
.
Comments
Post a Comment