I'm assuming by "hashed" you mean for storage purposes - i.e. not
simply .GetHashCode(); anyway, picking the simplest option (MD5),
something like:
using System;
using System.Security.Cryptography;
using System.Text;
using System.Xml;
static class Program
{
static void Main()
{
string text = "abcdefghijklmnopqrstuvwxyz";
MD5CryptoServiceProvider crypt = new
MD5CryptoServiceProvider();
byte[] inputBuffer = Encoding.UTF8.GetBytes(text);
byte[] hashBuffer = crypt.ComputeHash(inputBuffer);
// result as base-64 (easy & shorter result)
string hashBase64 = Convert.ToBase64String(hashBuffer);
// result as hex-string (more common)
StringBuilder sb = new StringBuilder(hashBuffer.Length * 2);
foreach (byte b in hashBuffer)
{
sb.Append(b.ToString("x2"));
}
string hashHex = sb.ToString();
}
}
Note, however, that MD5 is not very sucure; there are databases
dedicated to known MD5 values, so it shouldn't be used to hash
passwords or credit-card numbers, etc. For secure applications, you'd
want to look at a keyed algorithm - such as any of the HMACSHA[n]
implementations:
http://msdn2.microsoft.com/en-us/lib....hmacsha1.aspx
Marc