实例一(AES_ENCRYPT/AES_DECRYPT)
[study_db]> INSERT INTO book_classify
-> (classify_id, classify_name, description)
-> VALUES
-> (100, 'AES', AES_ENCRYPT(123, 'KEY'));
Query OK, 1 row affected (0.01 sec)
MariaDB [study_db]> SELECT classify_id, classify_name, description,
-> AES_DECRYPT(description, 'KEY')
-> FROM book_classify
-> WHERE classify_id = 100;
+-------------+---------------+------------------+---------------------------------+
| classify_id | classify_name | description | AES_DECRYPT(description, 'KEY') |
+-------------+---------------+------------------+---------------------------------+
| 100 | AES | ?^ڻIi?6wvn??a | 123 |
+-------------+---------------+------------------+---------------------------------+
1 row in set (0.00 sec)
*实例二(ENCODE/DECODE)
[study_db]> INSERT INTO book_classify
-> (classify_id, classify_name, description)
-> VALUES
-> (111, 'AES', ENCODE(123, 'KEY'));
Query OK, 1 row affected (0.00 sec)
MariaDB [study_db]> SELECT classify_id, classify_name, description,
-> DECODE(description, 'KEY')
-> FROM book_classify
-> WHERE classify_id = 111;
+-------------+---------------+-------------+----------------------------+
| classify_id | classify_name | description | DECODE(description, 'KEY') |
+-------------+---------------+-------------+----------------------------+
| 111 | AES | W? | 123 |
+-------------+---------------+-------------+----------------------------+
1 row in set (0.00 sec)
三, MD5加密
MD5主要用途:
1、对一段信息生成信息摘要,该摘要对该信息具有唯一性,可以作为数字签名。
2、用于验证文件的有效性(是否有丢失或损坏的数据),
3、对用户密码的,
4、在哈希函数中计算散列值
MD5是没有解密算法的,经常用来作为对账号密码的验证。验证的一般流程为:
1. 注册账号密码时对密码进行MD5加密,账号明文存入数据库,密码存入的是经过MD5加密的密文。
2. 登录时先根据账号,在数据库进行检测。
3. 检测到账号后对本次登录输入的密码进行MD5加密,拿本次密文与数据库里的密文进行验证。通过后即可成功登陆。