Оптимизация файлового потока для расшифровки файлов в VB.NET - PullRequest
0 голосов
/ 26 мая 2020

Я просто хочу попросить твоей помощи. Не могли бы вы подсказать мне, как я могу оптимизировать обработку файлового потока? Когда я обрабатываю расшифровку файлов размером 600 МБ, на завершение требуется 10 минут. Что-то не так с моими кодами?

Private Sub BGW_DoWork(sender As Object, e As DoWorkEventArgs) Handles BGW.DoWork
    Dim newWorer As BackgroundWorker = DirectCast(sender, BackgroundWorker)
    Dim counter As Double = 1
    Dim outputPath As String = txtOuput.Text
    Dim files = Directory.GetFiles(txtInput.Text, "*.ts")
    Dim key As Byte() = File.ReadAllBytes(txtKey.Text)
    Dim IV(15) As Byte

    Using outputStream As FileStream = New FileStream(outputPath, FileMode.Create, FileAccess.Write)
        For i As Integer = 0 To files.Length - 1
            Using inputStream As FileStream = New FileStream(files(i), FileMode.Open, FileAccess.Read, FileShare.Read, FileOptions.SequentialScan)

                Using AES As New AesManaged
                    AES.KeySize = 256
                    AES.BlockSize = 128
                    AES.Key = key
                    AES.IV = IV
                    AES.Padding = PaddingMode.PKCS7
                    AES.Mode = CipherMode.CBC

                    Using AESDecrypter As ICryptoTransform = AES.CreateDecryptor(AES.Key, AES.IV)

                        Using cryptoStream As CryptoStream = New CryptoStream(inputStream, AESDecrypter, CryptoStreamMode.Read, FileOptions.SequentialScan)

                            Dim value As Double = (counter / files.Length) * 100
                            newWorer.ReportProgress(value)

                            Dim PlaintextBytes(inputStream.Length - 1) As Byte
                            cryptoStream.CopyTo(outputStream, PlaintextBytes.Length)

                            counter += 1

                            cryptoStream.Dispose()
                            cryptoStream.Close()
                            inputStream.Close()
                            inputStream.Dispose()
                        End Using
                    End Using
                End Using
            End Using
        Next
        outputStream.Close()
        outputStream.Dispose()
    End Using
End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...