com.amx.duet.tools.security
Class AESCrypto

java.lang.Object
  extended bycom.amx.duet.tools.security.AESCrypto

public class AESCrypto
extends java.lang.Object

AESCrypto.java

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Optimised Java implementation of the AES(a.k.a. Rijndael) symmetric block cipher.

The AESCryto.java provides a "bare-bones" implementation of the AES algorithm suitable for J2ME or any other Java platform. This implementation meets the AES specification FIPS 197, found at http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf

For more information on the AES Algorithm (Rijndael), see http://csrc.nist.gov/archive/aes/index.html

AES (Rijndael) Symmetric Block Cipher

The AES algorithm is a symmetric block cipher that can encrypt (encipher) and decrypt (decipher) information.

The AES algorithm is capable of using cryptographic keys of 128, 192, and 256 bits to encrypt and decrypt data in blocks of 128 bits.

This particular implementation of AES uses the Electronic Codebook (ECB) mode of encryption in which each block of data is encrypted individually. If a single bit of the cipher text block is mangled, the entire corresponding plain text block will also be mangled.

Version:
1.0.1
Author:
CNina

Field Summary
static int BLOCK_BITS
          AES block size in bits
static int BLOCK_SIZE
          AES block size in bytes
static int DIR_BOTH
          Flag to setup both key schedules (encryption/decryption).
static int DIR_DECRYPT
          Flag to setup the decryption key schedule.
static int DIR_ENCRYPT
          Flag to setup the encryption key schedule.
 
Constructor Summary
AESCrypto()
           
 
Method Summary
 byte[] Decrypt(byte[] ciphertext)
          Decrypts some text.
 void decrypt(byte[] ct, byte[] pt)
          Decrypt exactly one block (BLOCK_SIZE bytes) of ciphertext.
 void dispose()
          Dispose of all sensitive information in this object.
 byte[] Encrypt(byte[] plaintext)
          Encrypts some text.
 void encrypt(byte[] pt, byte[] ct)
          Encrypt exactly one block (BLOCK_SIZE bytes) of plaintext.
 boolean isDisposed()
          If both the encryption and the decryption key schedules are null this method will return true otherwise false.
 void makeKey(byte[] cipherKey)
          Setup the AES key schedule (any cipher direction).
 void makeKey(byte[] cipherKey, int direction)
          Setup the AES key schedule for encryption, decryption, or both.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIR_ENCRYPT

public static final int DIR_ENCRYPT
Flag to setup the encryption key schedule.

See Also:
Constant Field Values

DIR_DECRYPT

public static final int DIR_DECRYPT
Flag to setup the decryption key schedule.

See Also:
Constant Field Values

DIR_BOTH

public static final int DIR_BOTH
Flag to setup both key schedules (encryption/decryption).

See Also:
Constant Field Values

BLOCK_BITS

public static final int BLOCK_BITS
AES block size in bits

See Also:
Constant Field Values

BLOCK_SIZE

public static final int BLOCK_SIZE
AES block size in bytes

See Also:
Constant Field Values
Constructor Detail

AESCrypto

public AESCrypto()
Method Detail

makeKey

public void makeKey(byte[] cipherKey,
                    int direction)
             throws java.text.ParseException
Setup the AES key schedule for encryption, decryption, or both.

Parameters:
cipherKey - the cipher key (128, 192, or 256 bits).
direction - cipher direction (DIR_ENCRYPT, DIR_DECRYPT, or DIR_BOTH).
Throws:
java.text.ParseException - If the key does not meet the length requirement.

makeKey

public void makeKey(byte[] cipherKey)
             throws java.text.ParseException
Setup the AES key schedule (any cipher direction).

Parameters:
cipherKey - the cipher key (128, 192, or 256 bits).
Throws:
java.text.ParseException - If the key does not meet the length requirement.

encrypt

public void encrypt(byte[] pt,
                    byte[] ct)
             throws java.lang.RuntimeException,
                    java.text.ParseException
Encrypt exactly one block (BLOCK_SIZE bytes) of plaintext.

Parameters:
pt - plaintext block.
ct - ciphertext block.
Throws:
java.lang.RuntimeException - If null encryption key schedule.
java.text.ParseException - If the plaintext does not meet the length requirements.

Encrypt

public byte[] Encrypt(byte[] plaintext)
               throws java.lang.RuntimeException
Encrypts some text. Returns Null if text to encrypt is null. The text to be encrypted is split into 16 byte blocks and each 16byte block is encrypted individualy. If the data does not completely fill 16 bytes, the data is shifted to the left and the block is padded to the right with zeroes (hex 0x00).

Returns:
ciphertext
Throws:
java.lang.RuntimeException - if null encryption key schedule.

decrypt

public void decrypt(byte[] ct,
                    byte[] pt)
             throws java.lang.RuntimeException,
                    java.text.ParseException
Decrypt exactly one block (BLOCK_SIZE bytes) of ciphertext.

Parameters:
ct - ciphertext block.
pt - plaintext block.
Throws:
java.lang.RuntimeException - If null decryption key schedule.
java.text.ParseException - If ciphertext does not meet the length requirement.

Decrypt

public byte[] Decrypt(byte[] ciphertext)
               throws java.text.ParseException
Decrypts some text. Returns Null if text to decrypt is null. The ciphertext length in bytes must be exact multiples of 16.

Parameters:
ciphertext -
Returns:
plaintext
Throws:
java.text.ParseException - If the ciphertext does not meet the length requirements.
java.lang.RuntimeException - if null decryption key schedule.

dispose

public final void dispose()
Dispose of all sensitive information in this object. Overrides the encryption key schedule (both directions) with zeroes (hex 0x00) once and sets it to null.


isDisposed

public final boolean isDisposed()
If both the encryption and the decryption key schedules are null this method will return true otherwise false. This method will verify if any sensitive information is still allocated.

Returns:
boolean


Copyright © 2008 AMX LLC. All Rights Reserved.