/// <summary> /// Decompresses a file using GZip decompression. /// </summary> /// <param name="inFile">Filepath of the file to be decompressed.</param> public static void Decompress(string inFile) { //Makes new FileInfo for the target file FileInfo fileToDecompress = new FileInfo(inFile); // Creates a FileStream containing the data from fileToDecompress using (FileStream originalFileStream = fileToDecompress.OpenRead()) { string currentFileName = fileToDecompress.FullName; string newFileName = currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length); // Creates the decompressed file stream using (FileStream decompressedFileStream = File.Create(newFileName)) { // Creates the compression stream using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress)) { // Decompresses file decompressionStream.CopyTo(decompressedFileStream); } } // Updates FileOP to the decompressed file FileOP.LoadFile(FileOP.GetFile().Remove(FileOP.GetFile().Length - fileToDecompress.Extension.Length)); } // Delete compressed file File.Delete(inFile); }
/// <summary> /// Compresses a file using GZip compression. /// </summary> /// <param name="inFile">Filepath of the file to be compressed.</param> public static void Compress(string inFile) { //Makes new FileInfo for the target file FileInfo fileToCompress = new FileInfo(inFile); // Creates a File Stream containing the data in the fileToCompress using (FileStream originalFileStream = fileToCompress.OpenRead()) { // Check that the file is not hidden or already a .gz file if ((File.GetAttributes(fileToCompress.FullName) & FileAttributes.Hidden) != FileAttributes.Hidden & fileToCompress.Extension != ".gz") { // Creates a File Stream for the compressed file using (FileStream compressedFileStream = File.Create(fileToCompress.FullName + ".gz")) { // Creates the compression stream using (GZipStream compressionStream = new GZipStream(compressedFileStream, CompressionMode.Compress)) { // Compresses file originalFileStream.CopyTo(compressionStream); } } } } // Delete uncompressed file File.Delete(inFile); // Updates the file FileOP.LoadFile(FileOP.GetFile() + ".gz"); }
private void StegExport_Click(object sender, EventArgs e) { if (FileOP.GetFile() != "") { StegExport frm = new StegExport(); frm.ShowDialog(); } }
/// <summary> /// Calls the save function when the user clicks the save file button. /// </summary> private void SaveButton_Click(object sender, EventArgs e) { if (FileOP.GetFile() != "") { DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1); UnlockFile(); FileOP.WriteToFile(dataTable); LockFile(); } }
private void button1_Click(object sender, EventArgs e) { FileOP.SelectKeyFile(); Crypto.EncryptFile(FileOP.GetFile(), FileOP.KeyFileToBits(FileOP.GetKeyFile())); FileOP.ClearKeyFile(); MasterForm frm = new MasterForm(); frm.Show(); frm.PerformRefresh(); this.Close(); }
private void PasswordOptions_FormClosing(object sender, FormClosingEventArgs e) { if (!success) { File.Delete(FileOP.GetFile()); FileOP.ClearFile(); FileOP.ClearKeyFile(); } else { success = false; } }
/// <summary> /// Unlocks the current file /// </summary> private void UnlockFile() { if (FileOP.GetKeyFile().Length > 0) { Crypto.DecryptFile(FileOP.GetFile(), FileOP.KeyFileToBits(FileOP.GetKeyFile())); CryptoProgBar.Value = 16; } Crypto.DecryptFile(FileOP.GetFile(), Crypto.mPassTemp); CryptoProgBar.Value = 33; Compressor.Decompress(FileOP.GetFile()); CryptoProgBar.Value = 50; }
/// <summary> /// Function for when the form closes. Asks the consumer if they would like to save the file they currently have open /// </summary> private void MasterForm_FormClosing(Object sender, FormClosingEventArgs e) { if (FileOP.GetFile() != "") { if (MessageBox.Show("Would you like to save the current working file?", "Close Program", MessageBoxButtons.YesNo) == DialogResult.Yes) { DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1); UnlockFile(); FileOP.WriteToFile(dataTable); LockFile(); } ClearMem(); } }
/// <summary> /// Lock and encrypt the currently open file. /// </summary> private void LockButton_Click(object sender, EventArgs e) { if (FileOP.GetFile() != "") { DialogResult savePrompt = MessageBox.Show("Would you like to save the current working file?", "Lock Current File", MessageBoxButtons.YesNo); if (savePrompt == DialogResult.Yes) { DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1); UnlockFile(); FileOP.WriteToFile(dataTable); LockFile(); } ClearMem(); } }
/// <summary> /// Sets the datagridviews datasource to be the datatable constructed by the readfile method. /// </summary> public void PerformRefresh(bool opened) { if (FileOP.GetFile() != "") { if (!opened) { UnlockFile(); } dataGridView1.DataSource = FileOP.ReadFile(); LockFile(); } else { dataGridView1.DataSource = null; } }
/// <summary> /// Locks the file when called /// </summary> private void LockFile() { //Compresses File Compressor.Compress(FileOP.GetFile()); CryptoProgBar.Value = 66; //Encrypt the file with stored password Crypto.EncryptFile(FileOP.GetFile(), Crypto.mPassTemp); CryptoProgBar.Value = 83; //If a Keyfile was used to open the file, use it to encrypt the file when locking if (FileOP.GetKeyFile().Length > 0) { //Encrypt the file with the KeyFile Crypto.EncryptFile(FileOP.GetFile(), FileOP.KeyFileToBits(FileOP.GetKeyFile())); CryptoProgBar.Value = 100; } CryptoProgBar.Value = 0; }
private void OkButton_Click(object sender, EventArgs e) { if ((PassEntry1.Text == PassEntry2.Text) && String.IsNullOrEmpty(PassEntry1.Text) == false && String.IsNullOrEmpty(PassEntry2.Text) == false) { if (KeyFileCheckBox.Checked) { if (FileOP.GetKeyFile() != "" && FileOP.GetKeyFile() != null && File.Exists(FileOP.GetKeyFile())) { Compressor.Compress(FileOP.GetFile()); Crypto.EncryptFile(FileOP.GetFile(), PassEntry1.Text); Crypto.EncryptFile(FileOP.GetFile(), FileOP.KeyFileToBits(FileOP.GetKeyFile())); KeyFileLocationText.Text = FileOP.GetKeyFile(); FileOP.ClearKeyFile(); MasterPasswordPrintPopUp printPopUp = new MasterPasswordPrintPopUp(PassEntry1.Text); printPopUp.ShowDialog(); FileOP.ClearFile(); this.Close(); } else { MessageBox.Show("Your key file is invalid. Please reselect your keyfile.", "File Error", MessageBoxButtons.OK); } } else { Compressor.Compress(FileOP.GetFile()); Crypto.EncryptFile(FileOP.GetFile(), PassEntry1.Text); MasterPasswordPrintPopUp printPopUp = new MasterPasswordPrintPopUp(PassEntry1.Text); printPopUp.ShowDialog(); FileOP.ClearFile(); this.Close(); } } else { string message = "Your passwords do not match or the boxes are blank. Please try entering them again"; string title = "Pass Keeper"; MessageBoxButtons buttons = MessageBoxButtons.OK; _ = MessageBox.Show(message, title, buttons); } }
private void Confirm_Click(object sender, EventArgs e) { if (KeyfileLocation.TextLength > 0) { if (!Crypto.DecryptFile(FileOP.GetFile(), FileOP.KeyFileToBits(KeyfileLocation.Text))) { MessageBox.Show("Inncorrect Credentials. Please Try Again.", "Access Denied", MessageBoxButtons.OK); KeyfileLocation.ResetText(); } else if (!Crypto.DecryptFile(FileOP.GetFile(), passwordEntry.Text)) { Crypto.EncryptFile(FileOP.GetFile(), FileOP.KeyFileToBits(KeyfileLocation.Text)); MessageBox.Show("Inncorrect Credentials. Please Try Again.", "Access Denied", MessageBoxButtons.OK); KeyfileLocation.ResetText(); } else { FileOP.LoadKeyFile(KeyfileLocation.Text); Crypto.mPassTemp = passwordEntry.Text; Compressor.Decompress(FileOP.GetFile()); TheParent.PerformRefresh(true); success = true; this.Close(); } } else if (!Crypto.DecryptFile(FileOP.GetFile(), passwordEntry.Text)) { MessageBox.Show("Inncorrect Credentials. Please Try Again.", "Access Denied", MessageBoxButtons.OK); KeyfileLocation.ResetText(); } else { Crypto.mPassTemp = passwordEntry.Text; Compressor.Decompress(FileOP.GetFile()); TheParent.PerformRefresh(true); success = true; this.Close(); } }
/// <summary> /// Logs the filepath to the console. Use for testing purposes. /// </summary> public static void PrintFileName() { Console.WriteLine(FileOP.GetFile()); }
/// <summary> /// Calls the select file method and shows the next form when the open button is clicked from the file dropdown menu. /// </summary> private void OpenFileDropDown_Click(object sender, EventArgs e) { // if there is currently a file open if (FileOP.GetFile() != "") { //open a dialog asking if the consumer would like to save DialogResult savePrompt = MessageBox.Show("Would you like to save the current working file?", "Lock Current File", MessageBoxButtons.YesNo); // save the file contents if (savePrompt == DialogResult.Yes) { DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1); UnlockFile(); FileOP.WriteToFile(dataTable); LockFile(); } // clear any references to file paths in the memory ClearMem(); } // if the dialog from fileOP returns true if (FileOP.SelectFile()) { // inflate the next form EnterPasswordForFile frm = new EnterPasswordForFile { TheParent = this }; // Adding all the enterPasswordForFile components to the list of components in the master from. // This is done to apply the same theme and text size to all of the forms textBoxes.AddRange(frm.enterPasswordForFileTextBoxes); labels.AddRange(frm.enterPasswordForFileLabels); this.buttons.AddRange(frm.enterPasswordForFileButtons); forms.Add(frm); // Changing theme of enterPasswordForFile if (darkThemeEnabled) { ChangeTheme(System.Drawing.Color.White, System.Drawing.Color.DarkGray, System.Drawing.Color.DarkSlateGray); frm.enterPasswordForFileDarkThemeEnabled = true; } else { ChangeTheme(System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Window, System.Drawing.SystemColors.Control); frm.enterPasswordForFileDarkThemeEnabled = false; } // Changing text size of enterPasswordForFile if (defaultTextSizeEnabled) { ChangeFontSize(8.0f); frm.enterPasswordForFileDefaultTextSizeEnabled = true; frm.enterPasswordForFileSmallTextSizeEnabled = false; frm.enterPasswordForFileLargeTextSizeEnabled = false; } else if (smallTextSizeEnabled) { ChangeFontSize(6.0f); frm.enterPasswordForFileDefaultTextSizeEnabled = false; frm.enterPasswordForFileSmallTextSizeEnabled = true; frm.enterPasswordForFileLargeTextSizeEnabled = false; } else if (largeTextSizeEnabled) { ChangeFontSize(10.0f); frm.enterPasswordForFileDefaultTextSizeEnabled = false; frm.enterPasswordForFileSmallTextSizeEnabled = false; frm.enterPasswordForFileLargeTextSizeEnabled = true; } frm.ShowDialog(); } }
/// <summary> /// Displays a warning to the user that they are about to create a new file. /// </summary> private void DisplayNewFileWarning() { string message = "Are you sure you wish to create a new password File?"; string title = "Pass Keeper"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; //creates a dialog box with the message, title and button options DialogResult confirm = MessageBox.Show(message, title, buttons); //if they want to make a new file if (confirm == DialogResult.Yes) { if (FileOP.GetFile() != "") { DialogResult savePrompt = MessageBox.Show("Would you like to save the current working file?", "Lock Current File", MessageBoxButtons.YesNo); if (savePrompt == DialogResult.Yes) { DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1); FileOP.WriteToFile(dataTable); } ClearMem(); } //call the create file method and inflate the next form if (FileOP.CreateFile()) { PasswordOptions passwordOptionsForm; // Creates a passwordOptions form with the correct theme if (darkThemeEnabled) { passwordOptionsForm = new PasswordOptions(Color.White, Color.DarkGray, Color.DarkSlateGray, darkThemeEnabled) { TheParent = this }; } else { passwordOptionsForm = new PasswordOptions(SystemColors.ControlText, SystemColors.Window, SystemColors.Control, darkThemeEnabled) { TheParent = this }; } // Adding all the password options components to the list of components in the master from. // This is done to apply the same theme and text size to all of the forms textBoxes.AddRange(passwordOptionsForm.passwordOptionsTextBoxes); labels.AddRange(passwordOptionsForm.passwordOptionsLabels); this.buttons.AddRange(passwordOptionsForm.passwordOptionsButtons); forms.Add(passwordOptionsForm); // Changing text size of passwordOptions if (defaultTextSizeEnabled) { ChangeFontSize(8.0f); passwordOptionsForm.passwordOptionsDefaultTextSizeEnabled = true; passwordOptionsForm.passwordOptionsSmallTextSizeEnabled = false; passwordOptionsForm.passwordOptionsLargeTextSizeEnabled = false; } else if (smallTextSizeEnabled) { ChangeFontSize(6.0f); passwordOptionsForm.passwordOptionsDefaultTextSizeEnabled = false; passwordOptionsForm.passwordOptionsSmallTextSizeEnabled = true; passwordOptionsForm.passwordOptionsLargeTextSizeEnabled = false; } else if (largeTextSizeEnabled) { ChangeFontSize(10.0f); passwordOptionsForm.passwordOptionsDefaultTextSizeEnabled = false; passwordOptionsForm.passwordOptionsSmallTextSizeEnabled = false; passwordOptionsForm.passwordOptionsLargeTextSizeEnabled = true; } passwordOptionsForm.ShowDialog(); passwordOptionsForm.Activate(); } ; } }