AES Encryption in Java

From NovaOrdis Knowledge Base
Revision as of 05:38, 24 November 2018 by Ovidiu (talk | contribs) (→‎Overview)
Jump to navigation Jump to search

Internal

Overview

AES supports key sizes of 16, 24 and 32 bytes (128, 192 and 256 bits).

Always use a fully qualified Cipher name. AES is not appropriate in such a case, because different JVMs/JCE providers may use different defaults for mode of operation and padding. Use AES/CBC/PKCS5Padding. Don't use ECB mode, because it is not semantically secure.

If you don't use ECB mode then you need to send the IV along with the ciphertext. This is usually done by prefixing the IV to the ciphertext byte array. The IV is automatically created for you and you can get it through cipherInstance.getIV()

Example

Playground AES Encryption