es.rediris.crypt
Class AESTool

java.lang.Object
  extended by es.rediris.crypt.AESTool

public class AESTool
extends Object

AESTool is a helper class for encrypting/decrypting messages using AES algorithm in ECB mode. Also, it uses PKCS5 padding when makes its operations with messages.
Keys are 128-bit, 192-bit or 256-bit blocks, and you have to associate a name for their. So, when you encrypt/decrypt you have to specify which key (through its name) you want to use.


Constructor Summary
AESTool()
          Generate an AESTool object
 
Method Summary
 boolean addKey(String name, byte[] key)
          Add a valid key setting its name.
 void clearKeys()
          Delete all added keys
 String decode(String nameKey, String data)
          Decrypt a message using the specified key
 boolean delKey(String name)
          Delete a previously added key
 String encode(String nameKey, String data)
          Encrypt a message using the specified key.
 byte[] getKey(String name)
           
 String[] getNameKeys()
          Get an array with the name of all added keys
 boolean hasKey(String nameKey)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AESTool

public AESTool()
Generate an AESTool object

Method Detail

addKey

public boolean addKey(String name,
                      byte[] key)
Add a valid key setting its name.

Parameters:
name - The name of the key
key - The array of bytes defining the key
Returns:
true if the key is valid and it wasn't previously added, false in other case

delKey

public boolean delKey(String name)
Delete a previously added key

Parameters:
name - The name of the key
Returns:
true if it has removed, false in other case

clearKeys

public void clearKeys()
Delete all added keys


getNameKeys

public String[] getNameKeys()
Get an array with the name of all added keys

Returns:
An array with their names

getKey

public byte[] getKey(String name)

encode

public String encode(String nameKey,
                     String data)
Encrypt a message using the specified key.

Parameters:
nameKey - The name of the key you want to use
data - The message you want to encrypt
Returns:
The ciphered message in base 64, or null if it has happened any error encrypting

decode

public String decode(String nameKey,
                     String data)
Decrypt a message using the specified key

Parameters:
nameKey - The name of the key you want to use
data - The ciphered message in base 64
Returns:
The "plain" message, or null if it has happened any error

hasKey

public boolean hasKey(String nameKey)