public void Cipher(PublicKey publicKey, IList <FileSystemEntity> inputFileEntities, string outputFileName)
        {
            if (inputFileEntities.Count == 0)
            {
                throw new ArgumentException(@"inputFileEntities is empty", "inputFileEntities");
            }
            var temporaryFileName = environmentHelper.GetTempFileName();

            try {
                fileUnifier.Union(inputFileEntities, temporaryFileName);
                rsaFileCipher.Cipher(publicKey, temporaryFileName, outputFileName);
                if (rsaFileCipher.Status == ProcessStatus.Stopped)
                {
                    messageHelper.Show("Process was stopped.", "Процесс был остановлен.");
                    rsaFileCipher.Restart();
                }
                if (rsaFileCipher.Status == ProcessStatus.Complete)
                {
                    messageHelper.Show("Process complete.", "Процесс завершен.");
                }
            } catch (SourceFileNotFoundException) {
                messageHelper.Show("Source file not found.", "Исходный файл не найден.");
            } catch (UnauthorizedAccessSourceFileException) {
                messageHelper.Show("Error when accessing the source file.", "Ошибка доступа к исходному файлу.");
            } catch (DestinationFileException) {
                messageHelper.Show("Error writing RSA file.", "Ошибка при записи RSA файла");
            } finally {
                environmentHelper.DeleteFile(temporaryFileName);
            }
        }
        public void Decipher(PrivateKey privateKey, string inputFileName, string outputDirectoryPath)
        {
            var temporaryFileName = environmentHelper.GetTempFileName();

            try {
                if (!Directory.Exists(outputDirectoryPath))
                {
                    Directory.CreateDirectory(outputDirectoryPath);
                }
                rsaFileDecipher.Decipher(privateKey, inputFileName, temporaryFileName);
                if (rsaFileDecipher.Status == ProcessStatus.Stopped)
                {
                    messageHelper.Show("Process was stopped.", "Процесс был остановлен.");
                    rsaFileDecipher.Restart();
                    return;
                }
                fileUnifier.Split(temporaryFileName, outputDirectoryPath);
                if (rsaFileDecipher.Status == ProcessStatus.Complete)
                {
                    messageHelper.Show("Process complete.", "Процесс завершен.");
                }
            } catch (IncorrectPrivateKeyException) {
                messageHelper.Show("Incorrect private key.", "Неправильный закрытый ключ.");
            } catch (TooHighVersionException) {
                messageHelper.Show("To decrypt a file needs a new program.", "Для расшифровки файла нужна более новая программа.");
            } catch (UnauthorizedAccessDestinationFileException) {
                messageHelper.Show(@"Error writing destination file.", "Ошибка при записи файла.");
            } catch {
                messageHelper.Show("Error decipher RSA file.", "Ошибка при расшифровке RSA файла.");
            } finally {
                environmentHelper.DeleteFile(temporaryFileName);
            }
        }
        public void Decipher(PrivateKey key, string sourceFileName, string destinationFileName)
        {
            var temporaryFileName = environmentHelper.GetTempFileName();

            try {
                zipAlgorithm.DecompressFile(sourceFileName, temporaryFileName);
                rsaFileDecipher.Decipher(key, temporaryFileName, destinationFileName);
            } finally {
                environmentHelper.DeleteFile(temporaryFileName);
            }
        }
Example #4
0
        public void Cipher(PublicKey key, string sourceFileName, string destinationFileName)
        {
            var temporaryFile = environmentHelper.GetTempFileName();

            try {
                rsaFileCipher.Cipher(key, sourceFileName, temporaryFile);
                zipAlgorithm.CompressFile(temporaryFile, destinationFileName);
            } finally {
                environmentHelper.DeleteFile(temporaryFile);
            }
        }