MySQL加密解密

1. 加密:mysql323,不可逆mysql

select old_password('bbs.antian365.com');
# 10c886615b135b38

 

2. 加密:mysqlsha1,不可逆sql

select password('bbs.antian365.com');
# *A2EBAE36132928537ADA8E6D1F7C5C5886713CC2

 

3. 加密:md5,不可逆windows

select md5('bbs.antian365.com');
# 3e8ec6f4db678dc7bf9ef71cd6c8b266

 

4. 加密解密: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下的密码明文。

查看密码明文:加密

 

5. 加密解密:aes_encrypt()和aes_decrypt()spa

都有两个参数,第一个是实际须要保存的值,第二个是盐。code

比encode()和decode()安全性要高。有说,在windows下不可用,我在windows下测试,能够正常执行。blog

        # 测试表,一样使用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';

 查看密码明文:md5

相关文章
相关标签/搜索