[C#] MD5編碼

  • 1501
  • 0

C# MD5 編碼的處理方式

1. Web 專案可以直接使用下列方法

string strMD5= System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("要加密的字串", "MD5");

2. 16位MD5加密法

MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
            
byte[] mData = md5Hasher.ComputeHash(Encoding.Default.GetBytes("要加密的字串"));
StringBuilder strMD5 = new StringBuilder();

for (int i = 0; i < mData.Length; i++)
{
    strMD5.Append(mData[i].ToString("x"));
}

3. 32位MD5加密法 

MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
byte[] mData = md5Hasher.ComputeHash(Encoding.Default.GetBytes("要加密的字串"));
StringBuilder strMD5 = new StringBuilder();

for (int i = 0; i < mData.Length; i++)
{
	strMD5.Append(mData[i].ToString("x2"));
}