C# SHA1 String Hashing
Sam's C# version could be marginally abbreviated (and much less legible). Which is virtually useless, although I would hope no one is writing one-time string hashing routines.
I'm sure it could probably be compressed further, but you have to give it to everything other than Java for providing more convenient abstractions. To my way of thinking, string -> hashed string is probably one of the more common uses of the hashing service providers.
using System;
using System.Security.Cryptography;
using System.Text;
public class ConsoleOutput
{
static void Main(string[] args)
{
Console.Write(HashUtils.GetSHA("It's just data"));
}
}
public class HashUtils
{
protected HashUtils() {}
public static string GetSHA(string source)
{
return BitConverter.ToString(new SHA1CryptoServiceProvider().ComputeHash(
Encoding.Default.GetBytes(source))).Replace("-", String.Empty);
}
}