0
P Narasimha,
Reason is your CryptoStream isn't flushing all it's data to the MemoryStream before it was being read, and closing the stream causes it to flush everything to the backing stream.
So, if your padding is invalid, close or call FlushFinalBlock
on any CryptoStream
performing encryption before you access the encrypted data. Flush
isn't enough.