In 2012, the answer should go to GCM, if you do not have serious compatibility issues.
GCM is an authenticated encryption mode. It provides privacy (encryption), integrity and authentication (MAC) at a time.
So far, the normal modes of operation have been ECB (default is Java ), CBC, CTR, OFB, and some others. All of them provided only encryption. Confidentiality in itself is rarely used without integrity; it was necessary to combine such classic modes with integrity checks in a special way. Because cryptography is difficult to understand, often such combinations were unsafe, slower than necessary, or even both.
Authenticated encryption modes were (quite recently) created by cryptographers to solve this problem. GCM is one of the most successful: it was chosen by NIST , it is efficient, it does not have a patent, and it can carry Additional authenticated data (that is, data that remains clear, but for which you can authenticate). For other modes, see this excellent article by Matthew Green .
Getting started with your problems:
Padding: By default, Java uses the PKCS # 7 add-on. It works, but is often vulnerable to oracle indents that are best defeated by the MAC . GCM already implements MAC (called GMAC).
Authentication: AES-GCM uses only one AES key, not passwords. It will tell you if the AES key is incorrect or the payload has been tampered with, but such conditions are treated as one. Instead, you should use a suitable key derivation algorithm such as PBKDF2 or bcrypt to extract the AES key from the password. I don’t think it can always be determined whether the password was incorrect or the payload was changed, because the data necessary to verify the first one can always be corrupted. You can encrypt a small known string (with ECB AES), send it and use it to verify the password is correct.
Minimize overhead:. At the end of the day, all modes lead to the same overhead (about 10-20 bytes) if you want authentication. If you are not working with very small payloads, this point can be ignored.
Performance: GCM is pretty good in that it is an online mode (there is no need to buffer the entire payload, which means less memory), it is parallelized and requires one AES operation and one Galois multiplication by a plaintext block. Classic modes such as ECBs are faster (one AES operation for each block only), but - again - you must also consider integrity logic, which can be slower than GMAC.
Having said that, you need to know that GCM security is based on generating a good random number to create an IV.
SquareRootOfTwentyThree
source share