1 using System.Security.Cryptography; 2 using System.Text; 3 4 namespace Common 5 { 6 public class md5Helper 7 { 8 public string GetMd5(string txt) 9 {10 //創建md5對象11 MD5 md5 = MD5.Create();12 //將字符串轉成字節數組13 byte[] bs = Encoding.UTF8.GetBytes(txt);14 //加密15 byte[] bs2 = md5.ComputeHash(bs);16 //將字節數組轉成字符串17 StringBuilder sb = new StringBuilder();18 for (int i = 0; i < bs2.Length; i++)19 {20 sb.Append(bs2[i].ToString("X2")); //x小寫X大寫21 }22 return sb.ToString();23 }24 }25 }
新聞熱點
疑難解答