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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM