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);
        }
        private async Task Encrypt(FileInfo file, IProgress <long> progress, CancellationToken token)
        {
            Random       r          = new Random();
            int          seed       = r.Next(350000) + 258;
            long         updateTick = GetUpdateTick(file.Length);
            Queue <byte> buffer     = new Queue <byte>();


            EncryptMessage = "키 생성 중...";
            await Task.Delay(1);

            var keys = await ByteEncrypter.GenerateKeyPairs(seed);

            var encryptKey = keys[0];
            var decryptKey = keys[1];

            EncryptMessage = "키 생성 완료..";
            await Task.Delay(500);

            State       = RSA.EncryptionState.CreateMap;
            MaxProgress = 255;
            var map = await ByteEncrypter.CreateByteMap(encryptKey, progress);

            string encryptedFilePath  = $"{file.FullName}.encrypted";
            string decryptKeyFilePath = $"{file.FullName}.key";

            State       = RSA.EncryptionState.ConvertByte;
            MaxProgress = SelectedFileLength;
            await Task.Delay(500);

            using (var inStream = file.OpenRead())
            {
                using (var reader = new BinaryReader(inStream))
                {
                    using (var outStream = File.OpenWrite(encryptedFilePath))
                    {
                        using (var writer = new BinaryWriter(outStream))
                        {
                            timeHelper.Reset(SelectedFileLength);
                            for (long i = 0; i < SelectedFileLength; i++)
                            {
                                token.ThrowIfCancellationRequested();
                                byte b = reader.ReadByte();
                                buffer.Enqueue(map[b]);
                                if (i % updateTick == 0)
                                {
                                    while (buffer.Count > 0)
                                    {
                                        writer.Write(buffer.Dequeue());
                                    }
                                    buffer.Clear();
                                    progress.Report(i);
                                    await Task.Delay(1);
                                }
                            }
                            while (buffer.Count > 0)
                            {
                                writer.Write(buffer.Dequeue());
                            }
                            progress.Report(SelectedFileLength);
                        }
                    }
                }
            }
            await Task.Delay(500);

            EncryptMessage = "키 파일을 저장중입니다.";
            await Task.Delay(500);

            using (var fs = File.OpenWrite(decryptKeyFilePath))
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(fs, decryptKey);
            }

            var now = DateTime.Now;

            Completed?.Invoke("작업 완료", $"완료 시간 : {now}\n걸린 시간 : {(now - timeHelper.StartTime).TotalSeconds} 초");
            RefreshCurrentFolder();
        }