MySQL存储数据加密

加密方式主流的有两种

ENCODE 与 DECODE

# 建一张测试表
create table users(
username varchar(128), # 用户昵称
password blob #密码
) engine=innodb default charset=utf8;
# 插入一条测试语句
INSERT INTO users (username, password) VALUES ('john', ENCODE('guessme', 'salt'));
commit;
# 查询john的密码(用的mysql workbench)
select t.username, DECODE(t.password,'salt') as password from users t where t.username = 'john';
# 在查询结构的password值上,右键,'open value in viewer'。可以看到text TAB下的密码明文。

AES_ENCRYPT 与 AES_DECRYPT

这个加密方式的安全级别比encode高,在新版本的数据库中已经弃用encode与decode。
# 测试表,同样使用users
# 插入一条语句
INSERT INTO users (username, password) VALUES ('steven', aes_encrypt('password', 'salt'));
commit;
# 查询steven的密码(用的mysql workbench)
select t.username, aes_decrypt(t.password,'salt') as password from users t where t.username = 'steven';
posted @   看不见的R  阅读(1484)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示