C#完成的字符串轉MD5碼函數實例。本站提示廣大學習愛好者:(C#完成的字符串轉MD5碼函數實例)文章只能為提供參考,不一定能成為您想要的結果。以下是C#完成的字符串轉MD5碼函數實例正文
本文實例講述了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#法式設計有所贊助。