C# “Bad Data” exception when decrypting encrypted file?

Here: cryptostream. Write(byteArrayInput, 0, byteArrayInput. Length); fsIn.Close(); fsOut.Close(); You're closing fsOut directly, without closing cryptostream.

That means the crypto stream doesn't get the chance to flush any final blocks etc. Additionally: Use using statements instead of manually calling Close or Dispose You're currently calling Read once, and assuming it will read all the data - you're not checking the return value. (You're also removing the last byte of the input file for some reason... why?) In general, you should loop round, reading into a buffer and then writing out however many bytes you read, until the Read method returns 0. If you're using .

NET 4, Stream. CopyTo is your friend.

Thanks! I REALLY REALLY need to study this even more. I was experimenting with the code sample from MSDN without a clue to what they do exactly.

I called the FlushFinalBlock() to cryptostream and removed the - 1 from the input file and that solved it. Thanks! – Raphael Apr 8 at 7:05.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions