Last active
March 1, 2018 13:00
-
-
Save Go-Noji/34edcadbce1cb4acaa304686ecce4479 to your computer and use it in GitHub Desktop.
AES_ENCRYPTで暗号化したテーブルをORDER BYで正常に並び替える ref: https://qiita.com/Go-Noji/items/a233595832201b2ec5e9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS `user` ( | |
`id` INT(11) NOT NULL AUTO_INCREMENT, | |
`name` BLOB DEFAULT NULL, | |
`savings` BLOB DEFAULT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=InnoDB DEFAULT CHARSET = utf8 AUTO_INCREMENT = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO `user` (`name`, `savings`) | |
VALUES (AES_ENCRYPT('めぐろ', 'password'), AES_ENCRYPT(100000, 'password')), | |
(AES_ENCRYPT('しながわ', 'password'), AES_ENCRYPT(8000000, 'password')), | |
(AES_ENCRYPT('しぶや', 'password'), AES_ENCRYPT(200, 'password')), | |
(AES_ENCRYPT('いけぶくろ', 'password'), AES_ENCRYPT(-50000, 'password')), | |
(AES_ENCRYPT('えびす', 'password'), AES_ENCRYPT(7005000, 'password')), | |
(AES_ENCRYPT('おおさき', 'password'), AES_ENCRYPT(0, 'password')), | |
(AES_ENCRYPT('にしにっぽり', 'password'), AES_ENCRYPT(9, 'password')), | |
(AES_ENCRYPT('はらじゅく', 'password'), AES_ENCRYPT(-99999999, 'password')), | |
(AES_ENCRYPT('ごたんだ', 'password'), AES_ENCRYPT(777777777777, 'password')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT `id`, AES_DECRYPT(`name`, 'password'), AES_DECRYPT(`savings`, 'password') | |
FROM `user` | |
ORDER BY AES_DECRYPT(`savings`, 'password'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+----+---------------------------------+------------------------------------+ | |
| id | AES_DECRYPT(`name`, 'password') | AES_DECRYPT(`savings`, 'password') | | |
+----+---------------------------------+------------------------------------+ | |
| 4 | いけぶくろ | -50000 | | |
| 8 | はらじゅく | -99999999 | | |
| 6 | おおさき | 0 | | |
| 1 | めぐろ | 100000 | | |
| 3 | しぶや | 200 | | |
| 5 | えびす | 7005000 | | |
| 9 | ごたんだ | 777777777777 | | |
| 2 | しながわ | 8000000 | | |
| 7 | にしにっぽり | 9 | | |
+----+---------------------------------+------------------------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT `id`, AES_DECRYPT(`name`, 'password'), AES_DECRYPT(`savings`, 'password') | |
FROM `user` | |
ORDER BY CAST(AES_DECRYPT(`savings`, 'password') AS SIGNED); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+----+---------------------------------+------------------------------------+ | |
| id | AES_DECRYPT(`name`, 'password') | AES_DECRYPT(`savings`, 'password') | | |
+----+---------------------------------+------------------------------------+ | |
| 8 | はらじゅく | -99999999 | | |
| 4 | いけぶくろ | -50000 | | |
| 6 | おおさき | 0 | | |
| 7 | にしにっぽり | 9 | | |
| 3 | しぶや | 200 | | |
| 1 | めぐろ | 100000 | | |
| 5 | えびす | 7005000 | | |
| 2 | しながわ | 8000000 | | |
| 9 | ごたんだ | 777777777777 | | |
+----+---------------------------------+------------------------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * | |
FROM `user`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+----+------------------+------------------+ | |
| id | name | savings | | |
+----+------------------+------------------+ | |
| 1 | ラjZヤ:,X8蕃・| 9ヨfノ殉「タ$uj | | |
'ン鋗ワ」 |。=截サチヌ難寛襯 | エ^ワw2-ス | |
| 3 | ィ>ケヒ"#p鬘~禽ゥ/ノ | クソスr 竓倢Hヲヌ | | |
| 4 | /妻フト4オ・ ィeレワ | U・マ{uwI・ルgs | | |
諚k7#ュネタコ2ル」 |0・ユ>シ | ソ | |
| 6 | 僴嶸b・Vオ|"ケ・ヤ | M・スcハハ?"・ | | |
| 7 | 穆wC、ー1J瞹*IェLヘ | 倭Gホチマ-jエp煉 | | |
| 8 | 鶴」錠ニo・=アリハ | <Kヲ嚔・⑰TLq | | |
| 9 | ∑・'N確aイ・」Т | ,0'アーョ&|d_・| | |
+----+------------------+------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT `id`, AES_DECRYPT(`name`, 'password'), AES_DECRYPT(`savings`, 'password') | |
FROM `user`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+----+---------------------------------+------------------------------------+ | |
| id | AES_DECRYPT(`name`, 'password') | AES_DECRYPT(`savings`, 'password') | | |
+----+---------------------------------+------------------------------------+ | |
| 1 | めぐろ | 100000 | | |
| 2 | しながわ | 8000000 | | |
| 3 | しぶや | 200 | | |
| 4 | いけぶくろ | -50000 | | |
| 5 | えびす | 7005000 | | |
| 6 | おおさき | 0 | | |
| 7 | はらじゅく | -99999999 | | |
| 8 | ごたんだ | 99999999999999 | | |
+----+---------------------------------+------------------------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT `id`, AES_DECRYPT(`name`, 'password'), AES_DECRYPT(`savings`, 'password') | |
FROM `user` | |
ORDER BY `name`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+----+---------------------------------+------------------------------------+ | |
| id | AES_DECRYPT(`name`, 'password') | AES_DECRYPT(`savings`, 'password') | | |
+----+---------------------------------+------------------------------------+ | |
| 6 | おおさき | 0 | | |
| 4 | いけぶくろ | -50000 | | |
| 2 | しながわ | 8000000 | | |
| 5 | えびす | 7005000 | | |
| 9 | ごたんだ | 777777777777 | | |
| 7 | にしにっぽり | 9 | | |
| 3 | しぶや | 200 | | |
| 1 | めぐろ | 100000 | | |
| 8 | はらじゅく | -99999999 | | |
+----+---------------------------------+------------------------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT `id`, AES_DECRYPT(`name`, 'password'), AES_DECRYPT(`savings`, 'password') | |
FROM `user` | |
ORDER BY AES_DECRYPT(`name`, 'password'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+----+---------------------------------+------------------------------------+ | |
| id | AES_DECRYPT(`name`, 'password') | AES_DECRYPT(`savings`, 'password') | | |
+----+---------------------------------+------------------------------------+ | |
| 4 | いけぶくろ | -50000 | | |
| 5 | えびす | 7005000 | | |
| 6 | おおさき | 0 | | |
| 9 | ごたんだ | 777777777777 | | |
| 2 | しながわ | 8000000 | | |
| 3 | しぶや | 200 | | |
| 7 | にしにっぽり | 9 | | |
| 8 | はらじゅく | -99999999 | | |
| 1 | めぐろ | 100000 | | |
+----+---------------------------------+------------------------------------+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment