I am trying to decrypt and encrypt datas with AESManaged or RijndaelManaged in VB.NET. I have a data packet which size is not multiple of block size. In this situation, it gives error as "Length of the data to decrypt is invalid" when I try to decrypt. I can only decrypt it if I remove the deficient block at the end of the data. But I need to know what lies on the last block.
So
Is it possible to decrypt the data which size isn't multiple of block size?
If it is, how can I do that?
Edit:
There are some informations those I forgot to write.
Block cipher mode must be CBC. Because I can decrypt all datas successfully except last bytes.
There is a client that can decrypt whole data. I found asm codes of the decryptor function. If I understand it right, it works like this:
x = deficient block size (x < 16)
buffer = an array sized as (16 + x)
- First the function grabs previous undecrypted bytes and put it to first 16 bytes of the buffer. (16 bytes)
- Appends undecrypted last bytes to buffer. (x bytes)
- Decrypts from buffer[x] to the end of the buffer and put the result to the same place. (last 16 bytes of buffer)
- Decrypts from buffer[0] to buffer[15] and put the result to the same place. (first 16 bytes of buffer)
- As you know, CBC xors decrypted bytes with previous decrypted bytes. So the function xors first x bytes of buffer with last x bytes of buffer.
Is there a way that I can decrypt last bytes like this in .NET?