Sign up for our newsletter and receive a free copy of our book .NET Web Application Logging Essentials
"What a great idea, ELMAH (Error Logging) for .NET in the cloud."
Online MD5 Hashing Tool
MD5 is a commonly used hashing function which outputs a 128-bit hash value. Hashing a string with MD5 multiple times will always produce the same 128-bit value. This makes MD5 ideal for hashing passwords or similar. Several services use MD5 to hide original string values as well, like Gravatar which accepts emails as MD5 values to avoid sending email addresses over the network.
With this free MD5 encoder, you can easily generate a hash from a string of your choice. If you look in the code examples below, adding MD5 encoding capabilities to your programs can be easily done using a few lines of C# code.
We monitor your websites for crashes and availability. This helps you get an overview of the quality of your applications and to spot trends in your releases.
We notify you when errors starts happening using Slack, Microsoft Teams, mail or other forms of communication to help you react to errors before your users do.
We help you fix bugs quickly by combining error diagnostic information with innovative quick fixes and answers from Stack Overflow and social media.
.NET and C# has built-in support for generating a MD5 hash using the System.Security.Cryptography.MD5
class:
var input = @"";
using (var md5 = MD5.Create())
{
var output = md5.ComputeHash(Encoding.Default.GetBytes(input.ToLower()));
}
// Produces:
The type of output
is an array of bytes but can be converted back to a string using the following code:
var sb = new StringBuilder(output.Length * 2);
for (var i = 0; i < output.Length; i++)
{
sb.Append(output[i].ToString("X2"));
}
var md5Hash = sb.ToString().ToLower();
If you are hashing strings to MD5 in multiple locations, you might want to consider adding this class in a shared project or similar:
public static class StringExtensions
{
public static string ToMD5(this string input)
{
if (string.IsNullOrWhiteSpace(input)) return string.Empty;
var loweredBytes = Encoding.Default.GetBytes(input.ToLower());
using (var md5 = MD5.Create())
{
var output = md5.ComputeHash(loweredBytes);
var sb = new StringBuilder(output.Length * 2);
for (var i = 0; i < output.Length; i++)
{
sb.Append(output[i].ToString("X2"));
}
return sb.ToString().ToLower();
}
}
}
// Usage: "Hello World".ToMD5();
With this extension method you can easily create an MD5 hash of any string in your application.