+2  A: 

I've never done any Objective-C programming, but I'm almost positive that you're using AES in different modes in your code. You need to make sure these are consistent. The default is probably Cipher Block Chaining (CBC) mode. Make sure you set this option in your Java code.

By the way, CBC mode should have a randomized Initialization Vector (IV) rather than NULL (which I assume uses all zeros). This too would need to be consistent across both.

I'm obliged to give standard disclaimer with cryptography that it's usually much safer to use a higher level protocol that handles this stuff for you like SSL/TLS for data in transit and something like Keyczar for data at rest. Getting crypto right is really hard and a tiny error (like picking a bad mode) can totally destroy the security of the system.

Jeff Moser
thanks for your answer! i will check that now
JonLOo
man I love you :) actually the problem was i was passing just the kCCOptionPKCS7Padding option to the CCCrypt function where i have to pass kCCOptionPKCS7Padding | kCCOptionECBMode option anyway thanks, your answer saved my day :)
JonLOo
You're welcome. Keep in mind that as I mentioned before, you really shouldn't use ECB mode. If at all possible use something like CBC. See Act 3, Scene 21 of http://www.moserware.com/2009/09/stick-figure-guide-to-advanced.html (direct link: http://4.bp.blogspot.com/_Zfbv3mHcYrc/SrfI0ckVcMI/AAAAAAAABss/wUh6hWmtNaU/s1600-h/aes_act_3_scene_21_modes_1100.png )
Jeff Moser
the problem is that ECB mode seems to be the only way supported in obj-c
JonLOo
According to http://www.opensource.apple.com/source/CommonCrypto/CommonCrypto-36064/CommonCrypto/CommonCryptor.h , the default (if you don't specify a mode) is CBC. I'd use that. "kCCOptionPKCS7Padding" is fine to use as well. Just make sure you do the same on the Java side. Additionally, you should be using a randomized initialization vector (the Java side will need to know this too)
Jeff Moser