views:

1005

answers:

3

Hi, I want to know which padding modes for AES encryption are common in both java and C#.NET

Thanks Bapi

A: 

A couple padding algorithms are outlined at Wikipedia. I have seen PKCS7 used in some significant applications (the Oracle client, for example). It's dead simple to implement, so you wouldn't have to worry if either platform does not support it out of the box.

Adam Paynter
+1  A: 

None, PKCS7, Zeros

Dotnet supports these 3 as do all the JCE providers.

If you're looking for java<->.net AES I would recommend Bouncy Castle, they have libs for both free.

http://www.bouncycastle.org/

Brian Hedler
+1 for Bouncy Castle!
Adam Paynter
-1 for Bouncy Castle (serious bugs).If you develop a cryptographic application then it is a good idea to make it independent of the provider. The JCE is well designed to do that. Then test with various providers.
Accipitridae
@Acc , there aren't many options of cross .net / java libs other than bouncy castle ... if you know of anything better you should have left a more helpful comment
Brian Hedler
I am trying to use bouncycastle but the documentation / examples seem to be severely lacking.
Nippysaurus
A: 

I was working on a class project and figured out a few details the hard way. First, Java supports PKCS7 padding out of the box but under a different name. It's called PKCS5. Some programmers use Bouncy Castle because of the mistaken belief that Java does not support PKCS7, but supports a different (older) padding type. This shouldn't really matter, except that Bouncy Castle turned out to have terrible bugs. My project relied on their implementation of AES. While it works if you encrypt all the data at once with a single doFinal, encrypting blocks goes horribly wrong and the outcome even changes depending on the buffer size used to pass the data. Switching back to Sun's implementation gave the correct results with the same code. Needless to say, that costed us a few days of debugging.