public class AES
extends java.lang.Object
Illustrative code for the AES block cipher (Rijndael). Handles a single block encryption or decryption, with diagnostic logging of intermediate values if required.
AES is a block cipher with a key length of 16/24/32 bytes and a block length 16 bytes.
AES (Rijndael) was designed by Joan Daemen and Vincent Rijmen, and was accepted as the US NIST's Advanced Encryption Standard in 2000.
This is the slow, obvious code version, written to follow the algorithm specification as closely and clearly as possible. It's code was originally derived from the illustrative Rijndael Java implementation submitted to the AES process, and sourced from the Rijndael sample Java code, but has been extensively adapted by Lawrie Brown to suit the illustrative requirements of the crypto calc applets he has written for his Cryptography courses at ADFA. The code has been tested using the AES triples published in FIPS-197 App C.
| Modifier and Type | Field and Description |
|---|---|
static int |
BLOCK_SIZE
AES constants and variables.
|
static int |
COL_SIZE
Internal AES constants and variables.
|
static int |
KEY_LENGTH
AES constants and variables.
|
static int |
NUM_COLS
Internal AES constants and variables.
|
static int |
ROOT
Internal AES constants and variables.
|
static int |
ROUNDS
AES constants and variables.
|
| Constructor and Description |
|---|
AES() |
| Modifier and Type | Method and Description |
|---|---|
CharacterBuffer |
decode(java.lang.String data) |
byte[] |
decodeBlock(byte[] cipher)
AES decrypt 128-bit ciphertext using key previously set.
|
byte[] |
decodeBlock(char[] plain,
int from)
AES encrypt 128-bit plaintext using key previously set.
|
byte[] |
decodeString(java.lang.String value) |
CharacterBuffer |
encode(BufferedBuffer plain) |
CharacterBuffer |
encode(java.lang.String data) |
byte[] |
encodeBlock(byte[] plain)
AES encrypt 128-bit plaintext using key previously set.
|
byte[] |
encodeBlock(char[] plain,
int from)
AES encrypt 128-bit plaintext using key previously set.
|
static int |
getRounds(int keySize)
return number of rounds for a given AES key size.
|
void |
setKey(byte[] key)
Expand a user-supplied key material into a session key.
|
void |
setKey(java.lang.String key) |
public static final int ROUNDS
public static final int BLOCK_SIZE
public static final int KEY_LENGTH
public static final int COL_SIZE
public static final int NUM_COLS
public static final int ROOT
public static int getRounds(int keySize)
keySize - size of the user key material in bytes.public CharacterBuffer encode(BufferedBuffer plain)
public CharacterBuffer encode(java.lang.String data)
public byte[] encodeBlock(char[] plain,
int from)
Follows cipher specification given in FIPS-197 section 5.1 See pseudo code in Fig 5, and details in this section.
plain - the 128-bit plaintext value to encrypt.from - fromIndex of Arraypublic byte[] encodeBlock(byte[] plain)
Follows cipher specification given in FIPS-197 section 5.1 See pseudo code in Fig 5, and details in this section.
plain - the 128-bit plaintext value to encrypt.public CharacterBuffer decode(java.lang.String data)
public byte[] decodeString(java.lang.String value)
public byte[] decodeBlock(char[] plain,
int from)
Follows cipher specification given in FIPS-197 section 5.1 See pseudo code in Fig 5, and details in this section.
plain - the 128-bit plaintext value to encrypt.from - fromIndex of Arraypublic byte[] decodeBlock(byte[] cipher)
Follows cipher specification given in FIPS-197 section 5.3 See pseudo code in Fig 5, and details in this section.
cipher - the 128-bit ciphertext value to decrypt.public void setKey(java.lang.String key)
public void setKey(byte[] key)
throws java.lang.IllegalArgumentException
See FIPS-197 Section 5.3 Fig 11 for details of the key expansion.
Session keys will be saved in Ke and Kd instance variables, along with numRounds being the number of rounds for this sized key.
key - The 128/192/256-bit AES key to use.java.lang.IllegalArgumentException