不同形式,一樣結果
/// <summary> /// 獲取大寫的MD5簽名結果 /// </summary> /// <param name="encypStr"></param> /// <param name="charset"></param> /// <returns></returns> public static string GetMD5(string encypStr, string charset) { string retStr; MD5CryptoServiceProvider m5 = new MD5CryptoServiceProvider(); //創建md5對象 byte[] inputBye; byte[] outputBye; //使用GB2312編碼方式把字符串轉化為字節數組. try { inputBye = Encoding.GetEncoding(charset).GetBytes(encypStr); } catch (Exception ex) { inputBye = Encoding.GetEncoding("GB2312").GetBytes(encypStr); } outputBye = m5.ComputeHash(inputBye); m5.Clear(); retStr = System.BitConverter.ToString(outputBye); retStr = retStr.Replace("-", "").ToLower(); return retStr; } public static string md5(string str) { try { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] bytValue, bytHash; bytValue = System.Text.Encoding.UTF8.GetBytes(str); bytHash = md5.ComputeHash(bytValue); md5.Clear(); string sTemp = ""; for (int i = 0; i < bytHash.Length; i++) { sTemp += bytHash[i].ToString("X").PadLeft(2, '0'); } str = sTemp.ToLower(); } catch (Exception e) { Console.WriteLine(e.Message); } return str; }