C#用法
/**//// <param name="sDataIn">需要加密的字符串</param>
/// <param name="move">偏移量</param>
/// <returns>sDataIn加密後的字符串</returns>
public string GetMD5(string sDataIn, string move)
...{
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bytValue, bytHash;
bytValue = System.Text.Encoding.UTF8.GetBytes(move + sDataIn);
bytHash = md5.ComputeHash(bytValue);
md5.Clear();
string sTemp = "";
for (int i = 0; i < bytHash.Length; i++)
...{
sTemp += bytHash[i].ToString("x").PadLeft(2, ''0'');
}
return sTemp;
}
textBox1.Text = this.GetMD5("123456","");
結果: e10adc3949ba59abbe56e057f20f883e
另類應用
MD5另類用法
public class Md5Convert
...{
public static string GetMd5Str(string ConvertString)
...{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);
//t2 = t2.Replace("-", "");
return t2;
}
}
textBox1.Text = Md5Convert.GetMd5Str("123456");
結果: 49-BA-59-AB-BE-56-E0-57