private void Hashing_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker backgroundWorker = sender as BackgroundWorker; byte[] array = new byte[this._Hash.GetDigestSize()]; using (Stream stream = File.OpenRead(this.FileLocationTextBox.Text)) { long total_read = 0L; int read_block; while ((read_block = stream.Read(this._BlockSize, 0, this._BlockSize.Length)) > 0) { if (backgroundWorker.CancellationPending) { e.Cancel = true; Array.Clear(this._BlockSize, 0, this._BlockSize.Length); break; } this._Hash.BlockUpdate(this._BlockSize, 0, read_block); total_read += read_block; float progress = total_read / this._FileSize * 100; backgroundWorker.ReportProgress((int)progress); } } this._Hash.DoFinal(array, 0); Array.Clear(this._BlockSize, 0, this._BlockSize.Length); e.Result = HashFunctionList.ByteArrayToHexString(array); }
private void SaveButton_Click(object sender, EventArgs e) { if (this.HashValueTextBox.Text.Trim() == "") { MessageBox.Show(this, "Please hash a file first.", "Attention"); return; } string directoryName = Path.GetDirectoryName(this.FileLocationTextBox.Text); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(this.FileLocationTextBox.Text); try { string path = directoryName + "\\" + fileNameWithoutExtension + HashFunctionList.HashFileExtension(HashFunctionListComboBox.Text); File.WriteAllText(path, HashValueTextBox.Text); } catch { MessageBox.Show(this, "Can't save hash value.", "Attention"); } }