SPT Core API

com.sptci.util
Class AESEncrypt

java.lang.Object
  extended by com.sptci.util.Encrypt
      extended by com.sptci.util.AESEncrypt

public class AESEncrypt
extends Encrypt

A utility class used to implement AES encryption and decryption of strings.

The following shows sample use of this class:

   import com.sptci.util.AESEncrypt;

     ...
     AESEncrypt aes = new AESEncrypt();
     String secret = "my secret value";
     String key = "my secret key";
     byte[] encrypted = aes.encrypt( key, secret );
     ...
     String mysecret = aes.decrypt( key, encrypted );
 

© Copyright 2007 Sans Pareil Technologies, Inc.

Version:
$Id: AESEncrypt.java 4553 2008-12-24 10:34:16Z rakesh $
Author:
Rakesh Vidyadharan 2007-09-13

Field Summary
protected static String ALGORITHM
          The encryption algorithm to use to encrypt strings.
protected static String SCHEME
          The encryption scheme to use to encrypt strings.
 
Fields inherited from class com.sptci.util.Encrypt
ENCODING, KEY_LENGTH, keyLength
 
Constructor Summary
AESEncrypt()
          Default constructor.
AESEncrypt(int length)
          Designated constructor.
 
Method Summary
protected  byte[] crypt(String key, byte[] value, int mode)
          Encrypt/decrypt the specified value using the specified key.
 
Methods inherited from class com.sptci.util.Encrypt
decrypt, encrypt, getKey, handleException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALGORITHM

protected static final String ALGORITHM
The encryption algorithm to use to encrypt strings. "AES/CBC/PKCS5Padding"

See Also:
Constant Field Values

SCHEME

protected static final String SCHEME
The encryption scheme to use to encrypt strings. "AES"

See Also:
Constant Field Values
Constructor Detail

AESEncrypt

public AESEncrypt()
Default constructor. Create a new instance of the encrypter which uses keys of length Encrypt.KEY_LENGTH.


AESEncrypt

public AESEncrypt(int length)
Designated constructor. Create a new instance that uses the specified key length.

Parameters:
length - The length of the key to use for encryption and decryption
Method Detail

crypt

protected byte[] crypt(String key,
                       byte[] value,
                       int mode)
                throws InvalidKeyException,
                       BadPaddingException,
                       RuntimeException
Encrypt/decrypt the specified value using the specified key.

Specified by:
crypt in class Encrypt
Parameters:
key - The key to use to encrypt the value.
value - The value that is to be encrypted or decrypted.
mode - The operation mode of this cipher (this is one of the following: Cipher.ENCRYPT_MODE, Cipher.DECRYPT_MODE, Cipher.WRAP_MODE or Cipher.UNWRAP_MODE).
Returns:
The encrypted bytes.
Throws:
InvalidKeyException - If the given key is inappropriate for initializing the Cipher, or its keysize exceeds the maximum allowable keysize (as determined from the configured jurisdiction policy files).
BadPaddingException - Declared in underlying implementation but never raised in this method.
RuntimeException - If IllegalBlockSizeException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException are raised while encrypting or decrypting.
See Also:
Encrypt.getKey(java.lang.String)

SPT Core API