Creating an MD5 String Extension method in C#

Wednesday, August 12th, 2009

Extension methods in C# allow for some very useful additions to the base .NET string library, and I recently came across the need to have an MD5 of a string, so I figured it would be very useful to add it as an extension method.

This allows for you to use a string, defined as follows:
string temp = "My string"

And obtain the MD5 of the string by executing the following:
string md5 = temp.MD5();

Without further ado, here is the code. Please note that this will only work in .NET 3.5 and above.