private void CalculateInformation(bool isvsfe) { SetWindowStatus("Getting File Information"); string information = null; long size = new FileInfo(readypath).Length; string sizetext; if (size < 1024) { sizetext = size.ToString() + " bytes"; } else if (size < 1048576) { sizetext = (size / 1024).ToString() + " KB"; } else { sizetext = (size / 1048576).ToString() + " MB"; } if (isvsfe) { vsfeFile vsfeFile = new vsfeFile(); vsfeFile = ReadvsfeFile(readypath); information = "VSFE Description:\n" + vsfeFile.description + "\n"; } information = information + "File Name:\n" + Path.GetFileName(readypath) + "\nMD5:\n" + CalculateMD5(readypath) + "\nSize:\n" + sizetext + "\nModified:\n" + File.GetLastWriteTime(readypath) + "\nPath:\n" + readypath; FileInformation.Text = information; SetWindowStatus(); }
public void SavevsfeFile(string filepath, vsfeFile vsfeFile) { FileStream fstream = File.Open(filepath, FileMode.Create); BinaryFormatter binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(fstream, vsfeFile); fstream.Close(); }
public vsfeFile ReadvsfeFile(string filepath) { vsfeFile vsfeFile = new vsfeFile(); FileStream fstream = File.Open(filepath, FileMode.Open); BinaryFormatter binaryFormatter = new BinaryFormatter(); try { vsfeFile = (vsfeFile)binaryFormatter.Deserialize(fstream); } catch { vsfeFile.bytes = null; } fstream.Close(); return(vsfeFile); }
private void SaveFileButton_Click(object sender, EventArgs e) { GC.Collect(); byte[] passwordBytes = Encoding.UTF8.GetBytes(PasswordTextBox.Text); SaveFileDialog saveFileDialog1 = new SaveFileDialog(); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); if (radioEncrypt.Checked) { byte[] FileBytes = File.ReadAllBytes(readypath); SetWindowStatus("Encrypting..."); vsfeFile vsfeFile = new vsfeFile(); vsfeFile.filename = Path.GetFileName(readypath); if (FileDescriptionTextBox.Enabled == true) { vsfeFile.description = FileDescriptionTextBox.Text; } vsfeFile.bytes = AES_Encrypt(FileBytes, passwordBytes); FileBytes = null; GC.Collect(); //clear memory sw.Stop(); SetWindowStatus(); saveFileDialog1.Filter = "ViKTUK VSFE files (*.vsfe)|*.vsfe|All files (*.*)|*.*"; saveFileDialog1.ShowDialog(); if (saveFileDialog1.FileName != "") { SetWindowStatus("Saving file..."); sw.Start(); SavevsfeFile(saveFileDialog1.FileName, vsfeFile); sw.Stop(); SetWindowStatus(); MessageBox.Show("Operation completed successfully.\nIt took " + GetTimeString(sw), "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); } vsfeFile.bytes = null; } else { vsfeFile vsfeFile = new vsfeFile(); vsfeFile = ReadvsfeFile(readypath); if (vsfeFile.bytes != null) { SetWindowStatus("Decrypting..."); byte[] decrypted = AES_Decrypt(vsfeFile.bytes, passwordBytes); sw.Stop(); SetWindowStatus(); if (decrypted != null) { string filename = vsfeFile.filename; string fileext = Path.GetExtension(filename); saveFileDialog1.FileName = Path.GetFileNameWithoutExtension(filename); saveFileDialog1.Filter = fileext.Remove(0, 1).ToUpper() + " files (*" + fileext + ")|*" + fileext + "|All files (*.*)|*.*"; saveFileDialog1.ShowDialog(); if (saveFileDialog1.FileName != "") { SetWindowStatus("Saving file..."); sw.Start(); File.WriteAllBytes(saveFileDialog1.FileName, decrypted); sw.Stop(); SetWindowStatus(); MessageBox.Show("Operation completed successfully.\nIt took " + GetTimeString(sw), "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Decryption failed. Check your password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("It isn't VSFE file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } GC.Collect(); }