本文實例講述了C#實現的字符串轉MD5碼函數。分享給大家供大家參考,具體如下:
/*測試環境:WinXP SP3、Visual Studio 2008 SP1、Visual Studio 2010 SP1更新日期:2014-04-23*/public string CalculateMD5Hash(string input){  MD5 md5 = System.Security.Cryptography.MD5.Create();  byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(input);  byte[] hash = md5.ComputeHash(inputBytes);  // step 2, convert byte array to hex string  StringBuilder sb = new StringBuilder();  for (int i = 0; i < hash.Length; i++)  {  sb.Append(hash[i].ToString("X2"));  }  return sb.ToString();}//end func希望本文所述對大家C#程序設計有所幫助。
新聞熱點
疑難解答