private async Task Decrypt(FileInfo file, FileInfo key, IProgress <long> progress, CancellationToken token) { RSA.RSAKeyPair?decryptKey = null; DecryptMessage = "키 불러오는 중..."; await Task.Delay(500); using (var fs = key.OpenRead()) { BinaryFormatter bf = new BinaryFormatter(); decryptKey = bf.Deserialize(fs) as RSA.RSAKeyPair?; } string originalFileName; if (!ExtractFileName(file.Name, out originalFileName)) { DecryptMessage = "파일 이름이 올바르지 않습니다."; await Task.Delay(500); return; } string originalExtension = ExtractExtension(originalFileName); if (decryptKey != null) { SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = originalFileName; if (!string.IsNullOrWhiteSpace(originalExtension)) { sfd.Filter = $"Original File|*.{originalExtension}"; } if (sfd.ShowDialog() ?? false) { Queue <byte> buffer = new Queue <byte>(); saveFilePath = sfd.FileName; DecryptMessage = "키 불러오기 완료."; await Task.Delay(500); RSA.RSAKeyPair keyPair = decryptKey.Value; State = RSA.EncryptionState.CreateMap; MaxProgress = 255; var map = await Decrypter.CreateByteMap(keyPair, progress); var updateTick = EncryptViewModel.GetUpdateTick(EncryptedFileLength); State = RSA.EncryptionState.ConvertByte; MaxProgress = EncryptedFileLength; await Task.Delay(500); using (var inStream = file.OpenRead()) { using (var reader = new BinaryReader(inStream)) { using (var outStream = File.OpenWrite(saveFilePath)) { using (var writer = new BinaryWriter(outStream)) { timeHelper.Reset(EncryptedFileLength); for (long i = 0; i < EncryptedFileLength; i++) { token.ThrowIfCancellationRequested(); byte b = reader.ReadByte(); buffer.Enqueue(map[b]); if (i % updateTick == 0) { while (buffer.Count > 0) { writer.Write(buffer.Dequeue()); } progress.Report(i); buffer.Clear(); await Task.Delay(1); } } while (buffer.Count > 0) { writer.Write(buffer.Dequeue()); } progress.Report(EncryptedFileLength); } } } } DecryptMessage = "작업이 완료 되었습니다."; var now = DateTime.Now; Completed?.Invoke("작업 완료", $"완료 시간 : {now}\n걸린 시간 : {(now - timeHelper.StartTime).TotalSeconds} 초"); } else { DecryptMessage = "사용자가 작업을 취소했습니다."; } } else { DecryptMessage = "키가 잘못된 듯 합니다."; } await Task.Delay(500); }