// // HashGen // // $Id$ // using System; using System.IO; using System.Text; using System.Security.Cryptography; public class HashGen { public static Int32 Main(String[] args) { SHA1 sha1 = SHA1.Create(); MD5 md5 = MD5.Create(); foreach (String path in args) { WriteHash("SHA1", sha1, path); WriteHash("MD5", md5, path); } return 0; } public static void WriteHash(String hashName, HashAlgorithm hashAlg, String path) { using (FileStream fsTarget = new FileStream(path, FileMode.Open)) { using (StreamWriter fsWriter = new StreamWriter(new FileStream(path + "." + hashName.ToLowerInvariant(), FileMode.Create))) { fsWriter.Write("{0}({1})= ", hashName, Path.GetFileName(path)); Byte[] hash = hashAlg.ComputeHash(fsTarget); foreach (Byte b in hash) fsWriter.Write("{0:x2}", b); } } } }