Return to Snippet

Revision: 37016
at December 2, 2010 12:56 by housecor


Initial Code
/// <summary>
		///  Hash an input string and return the hash as a 32 character hexadecimal string.
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		public string MD5(string input)
		{
			byte[] textBytes = System.Text.Encoding.Default.GetBytes(input);
			try
			{
				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;
			}
		}

Initial URL

                                

Initial Description

                                

Initial Title
MD5 hash method

Initial Tags

                                

Initial Language
C#