Class Aes

java.lang.Object
com.codename1.security.Aes

public final class Aes extends Object

AES (FIPS 197) in CBC mode over whole 16 byte blocks, with no padding: the building block of formats that define their own padding or key handling, such as the PDF security handler. Runs on the client and on the backend.

The installed CryptoEngine does the work where the platform has a native cipher (the client ports and the backend); elsewhere, the JavaScript port among them, a portable Java implementation produces the same bytes. For authenticated encryption of application data on the client use Cipher instead.

byte[] key = new byte[16];
byte[] iv = new byte[16];
byte[] sealed = Aes.cbcEncrypt(key, iv, new byte[32]);
byte[] plain = Aes.cbcDecrypt(key, iv, sealed);
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    cbcDecrypt(byte[] key, byte[] iv, byte[] data)
    Decrypts data, a whole number of blocks, with key (16, 24 or 32 bytes) chained from the 16 byte iv.
    static byte[]
    cbcDecryptZeroIv(byte[] key, byte[] data)
    Decrypts data, a whole number of blocks, with key chained from an all-zero IV; the inverse of [#cbcEncryptZeroIv(byte[], byte[])].
    static byte[]
    cbcEncrypt(byte[] key, byte[] iv, byte[] data)
    Encrypts data, a whole number of blocks, with key (16, 24 or 32 bytes) chained from the 16 byte iv.
    static byte[]
    cbcEncryptZeroIv(byte[] key, byte[] data)
    Encrypts data, a whole number of blocks, with key chained from an all-zero IV, for protocols that fix the IV themselves (Oracle's O5LOGON sign-in).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • cbcEncrypt

      public static byte[] cbcEncrypt(byte[] key, byte[] iv, byte[] data)

      Encrypts data, a whole number of blocks, with key (16, 24 or 32 bytes) chained from the 16 byte iv.

      Throws
      • IllegalArgumentException: for a key, IV or data of the wrong length
    • cbcDecrypt

      public static byte[] cbcDecrypt(byte[] key, byte[] iv, byte[] data)

      Decrypts data, a whole number of blocks, with key (16, 24 or 32 bytes) chained from the 16 byte iv. Padding, if the format has any, is left for the caller to remove.

      Throws
      • IllegalArgumentException: for a key, IV or data of the wrong length
    • cbcEncryptZeroIv

      public static byte[] cbcEncryptZeroIv(byte[] key, byte[] data)

      Encrypts data, a whole number of blocks, with key chained from an all-zero IV, for protocols that fix the IV themselves (Oracle's O5LOGON sign-in). Never use it for data of your own: a fixed IV makes equal plaintexts encrypt alike. Runs in portable Java on every platform.

      Throws
      • IllegalArgumentException: for a key or data of the wrong length
    • cbcDecryptZeroIv

      public static byte[] cbcDecryptZeroIv(byte[] key, byte[] data)

      Decrypts data, a whole number of blocks, with key chained from an all-zero IV; the inverse of [#cbcEncryptZeroIv(byte[], byte[])].

      Throws
      • IllegalArgumentException: for a key or data of the wrong length