MySQL加密解密函数AES_ENCRYPTAES_DECRYPT 官⽅⽂档:
加密函数
AES_ENCRYPT(str,key)
例:select AES_ENCRYPT('字符串','mima');
mysql> select AES_ENCRYPT('字符串','mima');
+---------------------------------+
| AES_ENCRYPT('字符串','mima')    |
+---------------------------------+
| 6                    |
+---------------------------------+
1 row in set (0.00 sec)
在存⼊数据库的时候,转成⼗六进制
create table t2(c1 varchar(64);
空调有臭味insert into t2 select hex(aes_encrypt(('字符串'),'mima'));
mysql> select * from t2;
+----------------------------------+
| c1 |弦子资料
三国演义主要内容+----------------------------------+
| 36CD256BB4BD99CB184D089408954681 |
+----------------------------------+
1 row in set (0.00 sec)
解密函数 AES_DECRYPT(str,key)
白珍熙
解密之前先⽤huhex函数转⼀次国产奶粉排行榜十强
梁宏达 雷锋mysql> select aes_decrypt(unhex(c1),'mima') from t2;
+-------------------------------+
| aes_decrypt(unhex(c1),'mima') |
+-------------------------------+
| 字符串                        |
+-------------------------------+
1 row in set (0.00 sec)