MD5 hash function

In cryptography, MD5 (Message-Digest algorithm 5) is a widely used cryptographic hash function with a 128-bit hash value. As an Internet standard (RFC 1321), MD5 has been employed in a wide variety of security applications, and is also commonly used to check the integrity of files. An MD5 hash is typically a 32-character hexadecimal number. Recently, a number of projects have created MD5 “rainbow tables” which are easily accessible online, and can be used to reverse many MD5 hashes into strings that collide with the original input.” (source: Wikipedia).

To make a MD5 algorithm in C# you may use the MD5CryptoServiceProvider which is standard in the C# library:

public static string MD5(string text)
  byte[] textBytes = System.Text.Encoding.Default.GetBytes(text);
    System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler;
    cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider();
    byte[] hash = cryptHandler.ComputeHash(textBytes);
    string ret = “”;
    foreach (byte a in hash)
      if (a<16)         ret += "0" + a.ToString ("x");       else         ret += a.ToString ("x");     }     return ret ;   }   catch   {     throw;   } } [/sourcecode]

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in General .NET and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s