|
Revision 3582, 1.0 kB
(checked in by mayuki, 13 months ago)
|
|
lang/csharp/Tools: import HashGen?, mdumpfs
|
-
Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 | //
|
|---|
| 2 | // HashGen
|
|---|
| 3 | //
|
|---|
| 4 | // $Id$
|
|---|
| 5 | //
|
|---|
| 6 | using System;
|
|---|
| 7 | using System.IO;
|
|---|
| 8 | using System.Text;
|
|---|
| 9 | using System.Security.Cryptography;
|
|---|
| 10 |
|
|---|
| 11 | public class HashGen
|
|---|
| 12 | {
|
|---|
| 13 | public static Int32
|
|---|
| 14 | Main(String[] args)
|
|---|
| 15 | {
|
|---|
| 16 | SHA1 sha1 = SHA1.Create();
|
|---|
| 17 | MD5 md5 = MD5.Create();
|
|---|
| 18 | foreach (String path in args)
|
|---|
| 19 | {
|
|---|
| 20 | WriteHash("SHA1", sha1, path);
|
|---|
| 21 | WriteHash("MD5", md5, path);
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | return 0;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | public static void WriteHash(String hashName, HashAlgorithm hashAlg, String path)
|
|---|
| 28 | {
|
|---|
| 29 | using (FileStream fsTarget = new FileStream(path, FileMode.Open))
|
|---|
| 30 | {
|
|---|
| 31 | using (StreamWriter fsWriter = new StreamWriter(new FileStream(path + "." + hashName.ToLowerInvariant(), FileMode.Create)))
|
|---|
| 32 | {
|
|---|
| 33 | fsWriter.Write("{0}({1})= ", hashName, Path.GetFileName(path));
|
|---|
| 34 | Byte[] hash = hashAlg.ComputeHash(fsTarget);
|
|---|
| 35 | foreach (Byte b in hash)
|
|---|
| 36 | fsWriter.Write("{0:x2}", b);
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 | } |
|---|