好比數據表中有一個手機號碼字段是敏感字段,不想明文存儲,能夠是用MySQL的自帶的函數處理html
Table 12.17 Encryption Functionsmysql
Name | Description |
---|---|
AES_DECRYPT() |
Decrypt using AES |
AES_ENCRYPT() |
Encrypt using AES |
UNHEX() |
Return a string containing hex representation of a number |
HEX() |
Hexadecimal representation of decimal or string value |
利用thinkPHP5.0中簡單和MySQL交互sql
這樣後續系統中就 能夠 使用加密後的字段, 明文字段過渡完後能夠刪除函數
SQL 語句實現以下:加密
select AES_DECRYPT(UNHEX(encrypt_mobile),'WO_SHI_YAN_ZHI') as username from dd_user where username = '15800000001';3d
UPDATE `dd_user` SET `encrypt_mobile`= HEX(AES_ENCRYPT('15800000001','WO_SHI_YAN_ZHI')) WHERE `user_id` = 675509;code