// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Text; using System.Globalization; using System.Security.Cryptography; namespace E { public class Program { public static byte[] FromHex(string s) { byte[] ba = new byte[s.Length/2]; for(int i = 0; i < ba.Length; i++) { ba[i] = byte.Parse(s.Substring(2 * i, 2), NumberStyles.HexNumber); } return ba; } public static string HexSHA1(String s) { HashAlgorithm alg = new SHA1Managed(); byte[] b = FromHex(s.Replace(" ", "")); alg.TransformFinalBlock(b, 0, b.Length); return BitConverter.ToString(alg.Hash).Replace("-", ""); } public static void Main(string[] args) { Console.WriteLine(HexSHA1("bd713447 99d5c7fc dc45b59f a3b9ab8f 6a948bc5")); Console.WriteLine(HexSHA1("bd713447 99d5c7fc dc45b59f a3b9ab8f 6a948bc6")); } } }