Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class Aes
- Object
- Aes
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);Methods
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. |
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. |
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). |
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[])]. |
Inherited methods
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