MySQLで暗号化、復号化

* AES_ENCRYPT()/ AES_DECRYPT()などの暗号化関数を使用する

CREATE TABLE IF NOT EXISTS `user` (
	`user_id` VARCHAR(100) NOT NULL,
	`password` VARBINARY(200) NOT NULL,
	PRIMARY KEY (`user_id`)
)
COMMENT='ユーザ'
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=11;

INSERT INTO `user`(`user_id`,`password`) VALUES(`user1`,AES_ENCRYPT(`password1`,`ENCRYPT-KEY`));
INSERT INTO `user`(`user_id`,`password`) VALUES(`user2`,AES_ENCRYPT(`password2`,`ENCRYPT-KEY`));
INSERT INTO `user`(`user_id`,`password`) VALUES(`user2`,AES_ENCRYPT(`password3`,`ENCRYPT-KEY`));

SELECT `user_id`, AES_DECRPYPT(`password`, `ENCRYPT-KEY`) FROM `user`;