MD5 เป็นทางเลือกนึงครับ เเต่ข้อเสียคือ เข้ารหัสไปเเล้วเรา ไม่สามารถ Decrypt ข้อมูลกลับมาได้ เรียกได้ว่าเข้ารหัสเเล้วเข้ารหัสไปเลยครับ
เช่นพวก passsword ของ user ในเว็บของเรา หากวันนึง เขาเกิดลืมพาสเวิ์ด เเล้วเราจะส่ง password กลับไปให้ เเต่ข้อมูลถุกเข้ารหัสด้วย MD5 ก็คงต้องหาวิธีอื่นครับ เช่น gen password ใหม่ให้กับ user ไปเลย
Code: Select all
using System.Text;
using System.Security.Cryptography;
public void DoMD5(string input)
{
string encrypted = [color=#4000FF]EnCryptToMD5[/color](txtpassword.text);
Response.Write(encrypted );
}
public static string EnCryptToMD5(string input)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
bs = md5.ComputeHash(bs);
StringBuilder sb = new StringBuilder();
foreach (byte b in bs)
{
sb.Append(b.ToString("x2").ToLower());
}
return sb.ToString();
}