《MYSQL數(shù)據(jù)庫mysql加密與解密函數(shù)的用法》要點:
本文介紹了MYSQL數(shù)據(jù)庫mysql加密與解密函數(shù)的用法,希望對您有用。如果有疑問,可以聯(lián)系我們。
為大家介紹下mysql數(shù)據(jù)庫中的加密函數(shù):
PASSWORD():創(chuàng)建一個經(jīng)過加密的密碼字符串,適合于插入到MySQL的安全系
統(tǒng).該加密過程不可逆,和unix密碼加密過程使用不同的算法.主要用于MySQL的認(rèn)證系統(tǒng).
?
ENCRYPT(,):使用UNIX crypt()系統(tǒng)加密字符串,ENCRYPT()函數(shù)接收要加密的字符串和(可選的)用于加密過程的salt(一個可以唯一確定口令的字符串,就像鑰匙一樣),注意,windows上不支持.MYSQL必讀
ENCODE(,)?? DECODE(,):加密解密字符串.
該函數(shù)有兩個參數(shù):被加密或解密的字符串和作為加密或解密基礎(chǔ)的密鑰.Encode結(jié)果是一個二進(jìn)制字符串,以BLOB類型存儲.加密程度相對比較弱MYSQL必讀
MD5():計算字符串的MD5校驗和(128位)MYSQL必讀
SHA5():計算字符串的SHA5校驗和(160位)MYSQL必讀
以上兩個函數(shù)返回的校驗和是16進(jìn)制的,適合與認(rèn)證系統(tǒng)中使用的口令.MYSQL必讀
AES_ENCRYPT
AES_DECRYPT的例子:
?MYSQL必讀
注意:需要Linux 且 AES_ENCRYPT 加密結(jié)果最好也以BLOB類型存儲.MYSQL必讀
加密:
select?? aes_encrypt(name, 'password ');
解密:
select?? aes_decrypt(aes_encrypt(name, 'password '), 'password ');?
?
########################
How to Use MySQL's AES_ENCRYPT and AES_DECRYPT to Store Passwords in a DatabaseMYSQL必讀
Here's the scenario.? You are building a custom member login area to a website.? You need to store the user's name, email address and a password.? The name and email can be stored in 'plain text', but for added security, you want to store the password in an encrypted format (in case someone steals the database somehow, or just for your users' peace of mind).
This mini-tutorial assumes you already know how to connect to your database and work with php/mysql.?
The benefit of using AES_ENCRYPT and AES_DECRYPT is that you can both encrypt the password, then decrypt the password whenever necessary.? This is helpful if you ever want to display the password to the user in an email, or if you're encrypting other account information that you need to display.
View the code here.
1:? The Key
For this to work, you must define a "key" to use when encrypting and decrypting the information from the database.? It would be best to store this key somewhere on your server outside of the main directory in which you're working.? This key can be whatever you want it to be, but you must also reference the same key during encrypting and decryption.
$key = 'ASKSDFNSDFKEISDJAHDLDSDF1235UUUiidfsdf';
2:? Encrypt the password
mysql_query("INSERT INTO users (user_first, user_last, user_password) VALUES ('".$_POST['first']."','".$_POST['last']."',AES_ENCRYPT($_POST['password'],$key))");
3:? Decrypt the password
Now, to display the decrypted password, you'll need a query similar to the one below:
$password = mysql_fetch_row(mysql_query("SELECT AES_DECRYPT(user_password,'$key') FROM users WHERE user_id = 4"));
echo $password[0];
So, using AES_ENCRYPT and AES_DECRYPT can be very useful when you need to store encrypted information in a database as well as display the original, unencrypted information.? Remember, you must use a 'key' in order to "unlock" and display the encrypted information.MYSQL必讀
可以explain下,看下結(jié)果:
?MYSQL必讀
維易PHP培訓(xùn)學(xué)院每天發(fā)布《MYSQL數(shù)據(jù)庫mysql加密與解密函數(shù)的用法》等實戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/12746.html