private void GetHash(FileHash hasher, Label label, FileInfo fileInfo) { Action action; action = () => label.Text = "... computing ..."; this.BeginInvoke(action); hasher.GetHashString(fileInfo); action = () => label.Text = hasher.HashString; this.BeginInvoke(action); DecrementThreadsRemaining(); }
static void Main(string[] args) { string file; string skey; System.Console.Out.Write("Enter the Source File Path :"); file = System.Console.In.ReadLine(); if (0 == file.Length) { System.Console.Out.Write("Bye"); return; } System.Console.Out.Write("Enter the secret key (For no secret key just press <Enter>):"); skey = System.Console.In.ReadLine(); FileHash fh = new FileHash(); fh.SourceFile = file; byte[] hashbytes = fh.HashFile(skey); if (0 == hashbytes.Length) { System.Console.Out.Write("Failed to hash the file {0}", file); return; } System.Console.Out.Write("Hash/Message Digest :"); foreach (byte hashbyte in hashbytes) { Console.Out.Write("{0:x}", hashbyte); } //--------------------------------------------------- System.Console.Out.Write("\nEnter the File Path to store hash:"); file = System.Console.In.ReadLine(); if (0 == file.Length) { System.Console.Out.Write("Bye"); return; } if (false == fh.CreateHashFile(file, skey)) { System.Console.Out.Write("Failed to create the hash file {0}", file); return; } }
public MainForm() { InitializeComponent(); _MD5Hasher = new FileHash(new MD5CryptoServiceProvider()); _RIPEMD160Hasher = new FileHash(new RIPEMD160Managed()); _SHA1Hasher = new FileHash(new SHA1Managed()); _SHA256Hasher = new FileHash(new SHA256Managed()); _SHA384Hasher = new FileHash(new SHA384Managed()); _SHA512Hasher = new FileHash(new SHA512Managed()); _busy = false; _threadsRemaining = 0; _threadsRemainingLock = new object(); ThreadPool.SetMaxThreads(30, 30); ThreadPool.SetMinThreads(10, 10); }
static void Main(string[] args) { IFileHash fileHash = new FileHash(); string result; result = fileHash.getFilenameAsHash("hello.png"); Console.WriteLine(result); fileHash.setFileHash("bye.pdf"); fileHash.setFileHash("dog.bmp"); Console.WriteLine(fileHash.isFileHashed("bye.pdf")); Console.WriteLine(fileHash.isFileHashed("wolf.pdf")); Console.WriteLine(fileHash.isFileHashed("cat.bmp")); Console.WriteLine(fileHash.isFileHashed("dog.bmp")); Console.WriteLine(fileHash.getFilenameAsHash("cat.bmp")); Console.WriteLine(fileHash.getFilenameAsHash("dog.bmp")); fileHash.removeFileHash("cat.bmp"); fileHash.removeFileHash("dog.bmp"); }