MD5
public static string GetMd5Hash(string input)
{
try
{
var md5Hasher = MD5.Create();
var data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
var sBuilder = new StringBuilder();
foreach (var t in data)
{
sBuilder.Append(t.ToString("x2"));
}
return sBuilder.ToString();
}
catch (Exception ex)
{
MessageBox.Show("Error in GetMd5Hash: " + ex.Message);
return "";
}
}
public static bool VerifyMd5Hash(string input, string hash)
{
try
{
var hashOfInput = GetMd5Hash(input);
var comparer = StringComparer.OrdinalIgnoreCase;
return 0 == comparer.Compare(hashOfInput, hash);
}
catch (Exception ex)
{
MessageBox.Show("Error in VerifyMd5Hash: " + ex.Message);
return "";
}
}