I keep getting this \"The input data is not a complete block.\" error while decrypting. The function successfully encrypts plain text and puts the IV in a textbox. I am using t
There are multiple issues with your code.
In encryption function:
MemoryStream, so it gets created with fixed size and cannot be expanded by future padding. You should use New MemoryStream(datain.Length) instead.memorystream.Close() is issued and then the contents of memorystream.ToArray() is requested, — but without any explicit cstream.Close() invocation: that way the last blocks, including padding, are not actually written to memorystream. You should call cstream.Close() before extracting memorystream data.AesCryptoServiceProvider resources before closing both CryptoStream and MemoryStream.In decryption function:
decrypteddata is overestimated without taking padding into account. You should shrink this array based on the actual value returned by cryptostream.Read(…).AES.Clear() as above.Return Encoding.UTF8.GetString(decrypteddata.ToArray()) instead.After fixing those issues, I could run your program without any error.