1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
public static string MD5Hash(string text)
{
MD5CryptoServiceProvider md5 = MD5.Create() as MD5CryptoServiceProvider;
byte[] textBytes = Encoding.Unicode.GetBytes(text);
byte[] md5Bytes = md5.ComputeHash(textBytes);
string hash = ByteArrayToHexString(md5Bytes);
return hash;
}
private static string ByteArrayToHexString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
sb.AppendFormat("{0:X2}", bytes[i]);
}
return sb.ToString();
} |