mc-r

加密方式主流的有两种

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\';

分类:

技术点:

相关文章:

  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-08-14
  • 2022-12-23
猜你喜欢
  • 2022-01-16
  • 2022-01-20
  • 2021-10-15
  • 2021-11-14
  • 2021-12-26
  • 2022-02-22
  • 2022-01-22
相关资源
相似解决方案