/// <exception cref="ArgumentNullException">any argument is null</exception> /// <exception cref="ArgumentException">sourceFileName is empty or destinationFileName is empty</exception> /// <exception cref="SourceFileNotFoundException">Исходный файл не найден.</exception> /// <exception cref="UnauthorizedAccessSourceFileException">Ошибка при доступе к исходному файлу.</exception> /// <exception cref="DestinationFileException">Ошибка при сохранении зашифрованного файла.</exception> public void Cipher(PublicKey key, string sourceFileName, string destinationFileName) { Status = ProcessStatus.Processing; CurrentBlock = 0; try { var rsa = new RsaCipher(key); using (var reader = CreateFileReader(sourceFileName, key)) { TotalBlocks = Convert.ToInt32(Math.Ceiling((double)reader.Length / (key.N.Digit - 1))); using (var writter = factory.CreateRsaFileWriter(destinationFileName, (short)key.N.Digit)) { writter.WriteHeader(reader.Length, reader.HashCode); while (!reader.IsDone && Status != ProcessStatus.Stopped) { var number = reader.ReadNextBlock(); writter.WriteNextBlock(rsa.Cipher(number)); ++CurrentBlock; OnBlockCompleted(); } } } } catch (Exception) { Status = ProcessStatus.Stopped; throw; } if (Status == ProcessStatus.Processing) { Status = ProcessStatus.Complete; } }
public void Cipher3() { // p = 17 // q = 23 // n = p * q = 391 // e = 3 var data = BigNumber.FromBytes(new[] { 14, 1 }); var n = BigNumber.FromBytes(new[] { 135, 1 }); var e = BigNumber.FromBytes(new[] { 3 }); var key = new PublicKey(e, n); var rsa = new RsaCipher(key); var result = rsa.Cipher(data); CheckNumber(result, 60); }