private void DecryptClick(object sender, EventArgs e) { var D = (uint)numericUpDownD.Value; var fileInfoEncryptedFile = new FileInfo(textBoxFilePathEnryptedFile.Text); if (!fileInfoEncryptedFile.Exists) { throw new InvalidOperationException($"Lz77 decoding error: file '{fileInfoEncryptedFile.FullName}' does not exist"); } var encryptedFileExtension = GetExtensionOfEncryptedFile(fileInfoEncryptedFile); var decryptedFileDestinationPath = $"{fileInfoEncryptedFile.FullName}.{encryptedFileExtension}"; using (var fileReader = new FileReader(textBoxFilePathEnryptedFile.Text, new Buffer())) { using (var fileWriter = new FileWriter(decryptedFileDestinationPath, new Buffer())) { rsaDecrypter.DecryptFile(fileReader, fileWriter, D); } } if (checkBoxShowKeysDecoding.Checked) { DisplayKeys(rsaDecrypter.KeysFromLastRun, textBoxKeysDecrypt); } }
public void FileIsEncryptedThenDecryptedCorrectly() { using (var fileReader = new FileReader(filePathSource, new Buffer())) { using (var fileWriter = new FileWriter(filePathEncryptedFile, new Buffer())) { rsaEncrypter.EncryptFile(fileReader, fileWriter, Constants.N, Constants.E); } } using (var fileReader = new FileReader(filePathEncryptedFile, new Buffer())) { using (var fileWriter = new FileWriter(filePathDecryptedFile, new Buffer())) { rsaDecrypter.DecryptFile(fileReader, fileWriter, Constants.D); } } Assert.IsTrue(TestMethods.FilesHaveTheSameContent(filePathSource, filePathDecryptedFile)); }