У меня проблема. Я все еще не могу исправить
Я делаю функцию для расшифровки aes.
public static void AESDecrypt(byte[] keyFile, string fsInput, string fsOutput)
{
using (var AES = new AesCryptoServiceProvider())
{
AES.KeySize = 128;
AES.BlockSize = 128;
AES.Key = keyFile;
AES.IV = new byte[16];
AES.Mode = CipherMode.CBC;
AES.Padding = PaddingMode.PKCS7;
using (var streamOut = new FileStream(fsOutput, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
using (var streamIn = new FileStream(fsInput, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (var cs = new CryptoStream(streamOut, AES.CreateDecryptor(), CryptoStreamMode.Write))
{
byte[] buffer = new byte[65536]; //it's actually [4096] i just doing experiment
int bytesRead = 0;
do
{
bytesRead = streamIn.Read(buffer, 0, buffer.Length);
if (bytesRead != 0)
cs.Write(buffer, 0, bytesRead);
}
while (bytesRead != 0);
}
}
}
}
}
Вот моя проблема. с этим кодом из моей основной формы. Конечный результат не объединяется в один, он только расшифровывает последний файл из входных файлов (listviewitem).
outputPath = Path.Combine(txtOutputFolder.Text, txtOutputFilename.Text + ".ts");
foreach (object i in LV.Items)
{
sourceItems = (SourceItem)i;
string inputFiles = sourceItems.Filename;
await Task.Run(() => Decrypter.AESDecrypt(keyfile, inputFiles, outputPath), ct);
другие коды ......
}
Не могли бы вы скажите мне, что не так в моем основном коде?
Он работает, только если я использую что-то вроде этого. Но вместо этого я хочу поместить файловый поток в свою функцию.
using (FileStream fsOutput = new FileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
foreach (object i in LV.Items)
{
sourceItems = (SourceItem)i;
string inputFiles = sourceItems.Filename;
using (FileStream fsInput = new FileStream(inputFiles, FileMode.Open, FileAccess.Read, FileShare.Read))
{
//process begin
await Task.Run(() => Decrypter.AESDecrypt(keyfile, fsInput, fsOutput), ct);