ToMd5Hash

/// <summary>
/// Convert a input string to a byte array and compute the hash.
/// </summary>
/// <param name="value">Input string.</param>
/// <returns>Hexadecimal string.</returns>
public static string ToMd5Hash(this string value)
{
	if (string.IsNullOrEmpty(value))
	{
		return value;
	}

	using (MD5 md5 = new MD5CryptoServiceProvider())
	{
		byte[] originalBytes = ASCIIEncoding.Default.GetBytes(value);
		byte[] encodedBytes = md5.ComputeHash(originalBytes);
		return BitConverter.ToString(encodedBytes).Replace("-", string.Empty);
	}
}
Example:
string value = "this is a string";
Console.WriteLine(value.ToMd5Hash());

Description

Convert a input string to a byte array and compute the hash.

Details

Double click on the code to select all.

 

;