views:

2402

answers:

2

I am using AES/CBC/PKCS5Padding padding standard in java and my friend uses PKCS7 standard in c#.NET If My friend encrypt the data using AES and send me the key then I can decrypt it.

But If my data length increases more than 2920 bytes then if i encrypt the data in c#.NET and decrypt the data in java then my decryption does not work good. It gives me the following error.

"javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher"

Thanks Bapi

+1  A: 

You again forgot to flush the buffers which means that the data stream is incomplete.

[EDIT] I don't know about C# but in Java, you must call doFinal() once after all data has arrived. (See the docs).

The source of the problem is that the encryption API needs to know when you're done. It can't tell from the data, you must call a method to say "wrap it up, create the final checksum, whatever, so the receiver can decode it".

Aaron Digulla
How to flush the buffer?
Deepak
A: 

just use cipher.dofinal("Your byte array","offset...put 0","block size...16");

eg : c.dofinal(ByteArray,0,16);

Anish