当前位置:Gxlcms > 数据库问题 > MySQL数据库字段加密

MySQL数据库字段加密

时间:2021-07-01 10:21:17 帮助过:26人阅读

/*Table structure for table `test` */ DROP TABLE IF EXISTS `test`; CREATE TABLE `test` ( `id` int(10) NOT NULL AUTO_INCREMENT COMMENT 主键, `username` varchar(200) NOT NULL COMMENT 用户名, `mobile` varchar(100) NOT NULL COMMENT 电话号码, `enmobile` varbinary(100) NOT NULL COMMENT 加密后的电话号码, KEY `id` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
  1. <span style="color: rgba(0, 0, 0, 1)">二、插入一条数据
  2. INSERT INTO test(username,mobile,enmobile)VALUES
  3. (</span><span style="color: rgba(128, 0, 0, 1)">‘</span><span style="color: rgba(128, 0, 0, 1)">曹操</span><span style="color: rgba(128, 0, 0, 1)">‘</span>,<span style="color: rgba(128, 0, 0, 1)">‘</span><span style="color: rgba(128, 0, 0, 1)">17779740665</span><span style="color: rgba(128, 0, 0, 1)">‘</span>,AES_ENCRYPT(<span style="color: rgba(128, 0, 0, 1)">‘</span><span style="color: rgba(128, 0, 0, 1)">17779740665</span><span style="color: rgba(128, 0, 0, 1)">‘</span>,<span style="color: rgba(128, 0, 0, 1)">‘</span><span style="color: rgba(128, 0, 0, 1)">key</span><span style="color: rgba(128, 0, 0, 1)">‘</span>));
  1. <span style="color: rgba(0, 0, 0, 1)">三、对加密数据进行解密
  2. SELECT t1.</span>*,AES_DECRYPT(t1.`enmobile`,<span style="color: rgba(128, 0, 0, 1)">‘</span><span style="color: rgba(128, 0, 0, 1)">key</span><span style="color: rgba(128, 0, 0, 1)">‘</span>) AS <span style="color: rgba(128, 0, 0, 1)">‘</span><span style="color: rgba(128, 0, 0, 1)">解密后的电话号码</span><span style="color: rgba(128, 0, 0, 1)">‘</span><span style="color: rgba(0, 0, 0, 1)">
  3. FROM test t1;</span>

 

MySQL数据库字段加密

标签:into   sql数据库   exist   arc   binary   解密   arch   str   auto   

人气教程排行