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[]
    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.

    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