//Decrypt private void button2_Click(object sender, EventArgs e) { if (keySaltPath == null || keySaltPath == "") { MessageBox.Show("Please select a folder for Keys/Salts.", "Error"); return; } //Important Note: //As filename and extension are not preserved, these must be remembered/stored somewhere. //Some applications, mainly media, may infer the type from the header/structure and not require the extension. //While this code appears to support multiselect, it does not and should not be used anyway. selectedDestinationFiles.Add(listView2.SelectedItems[0].Text); for (int i = 0; i < selectedDestinationFiles.Count; i++) { byte[] encryptedFile = File.ReadAllBytes(selectedDestinationFiles[i]); for (int j = selectedKeysFiles.Count - 1; j >= 0; j--) { encryptedFile = CrystallineCipher.Decrypt(encryptedFile, File.ReadAllBytes(selectedKeysFiles[j]), File.ReadAllBytes(selectedSaltFiles[j]), (int)numericUpDown1.Value); } File.WriteAllBytes(sourcePath + "\\" + i + ".clc", encryptedFile); } UpdateFileViews(); }
//Encrypt private void button1_Click(object sender, EventArgs e) { if (keySaltPath == null || keySaltPath == "") { MessageBox.Show("Please select a folder for Keys/Salts.", "Error"); return; } //Important Note: //While this code is setup for multiselect that would result in key/salt reuse. //Multiselect has been disabled in the ListView to prevent this. //Always use a new destination folder for encrypt as file names are not preserved. //Every encrypted file will be called 0.cle. selectedSourceFiles.Add(listView1.SelectedItems[0].Text); for (int i = 0; i < selectedSourceFiles.Count; i++) { byte[] encryptedFile = File.ReadAllBytes(selectedSourceFiles[i]); for (int j = 0; j < selectedKeysFiles.Count; j++) { encryptedFile = CrystallineCipher.Encrypt(encryptedFile, File.ReadAllBytes(selectedKeysFiles[j]), File.ReadAllBytes(selectedSaltFiles[j]), (int)numericUpDown1.Value); } File.WriteAllBytes(destinationPath + "\\" + i + ".cle", encryptedFile); } UpdateFileViews(); }