public bool DecryptFile(string inputFile, string outputFile, string key, string iv) { FileStream fsInput = new FileStream(inputFile, FileMode.Open); FileStream fsOutput = new FileStream(outputFile, FileMode.Create); try { RijndaelManaged aes = new RijndaelManaged { IV = Crypto.ParseHexString(iv), Key = Crypto.ParseHexString(key), Mode = CipherMode.CFB, Padding = PaddingMode.None, }; ICryptoTransform encryptor = aes.CreateDecryptor(); using (MemoryStream memoryStream = new MemoryStream()) { int cut; using (CryptoStream output = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)) { cut = (int)(aes.BlockSize - fsInput.Length % aes.BlockSize); byte[] buffer = new byte[fsInput.Length + cut]; fsInput.Read(buffer, 0, buffer.Length); output.Write(buffer, 0, buffer.Length); } byte[] data = memoryStream.ToArray(); fsOutput.Write(data, 0, data.Length - cut); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Exception"); return false; } fsOutput.Flush(); fsOutput.Close(); return true; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionbyte[] buffer = new byte[fsInput.Length]; long bytesProcessed = 0; long fileLength = fsInput.Length; int bytesInCurrentBlock; do { bytesInCurrentBlock = fsInput.Read(buffer, 0, buffer.Length); cryptoStream.Write(buffer, 0, bytesInCurrentBlock); bytesProcessed = bytesProcessed + bytesInCurrentBlock; } while (bytesProcessed < fileLength);
int data; while ((data = fsInput.ReadByte()) != -1) cryptoStream.WriteByte((byte)data);