com.digitalsanctuary.atg.crypto
Class AbstractEncryptorComponent

java.lang.Object
  extended byatg.nucleus.GenericService
      extended bycom.digitalsanctuary.atg.crypto.AbstractEncryptorComponent
All Implemented Interfaces:
atg.nucleus.AdminableService, atg.nucleus.logging.ApplicationLogging, atg.nucleus.naming.ComponentNameResolver, java.util.EventListener, atg.naming.NameContextBindingListener, atg.naming.NameContextElement, atg.naming.NameResolver, atg.nucleus.Service, atg.nucleus.ServiceListener
Direct Known Subclasses:
AESEncryptorComponent

public abstract class AbstractEncryptorComponent
extends atg.nucleus.GenericService

This is an abstract class of an encryptor component.

Author:
Louis Baliotis

Field Summary
 
Fields inherited from class atg.nucleus.GenericService
CLASS_VERSION, SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
AbstractEncryptorComponent()
           
 
Method Summary
 java.lang.String computeMAC(java.lang.String pClearText)
          This method computes the MAC message signature for the clear text.
 byte[] decryptBytes(byte[] pBytesToDecrypt)
          This method takes in a byte array and decrypts it using the AES algorithm and the key used to setup this class.
 java.lang.String decryptString(java.lang.String pEncryptedContent)
          This method takes in a String of a Base64 encoded byte array of encrypted data and decrypts it using the AES algorithm and the key used to setup this class.
 void doStartService()
          This method sets up our component, and creates the Encryptor object.
 byte[] encryptBytes(byte[] pBytesToEncrypt)
          This method takes in a byte array and encrypts it using the AES algorithm and the key used to setup this class.
 java.lang.String encryptString(java.lang.String pUnencryptedContent)
          This method takes in a String and encrypts is using the AES algorithm and the key used to setup this class.
 AbstractEncryptor getEncryptor()
           
 java.lang.String getKey()
           
 void setEncryptor(AbstractEncryptor pEncryptor)
           
 void setKey(java.lang.String pKey)
           
abstract  void setupEncryptor()
          This method sets up the encryptor.
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStopService, getAbsoluteName, getAdminServlet, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingWarning, setServiceInfo, startService, stopService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractEncryptorComponent

public AbstractEncryptorComponent()
Method Detail

computeMAC

public java.lang.String computeMAC(java.lang.String pClearText)
                            throws EncryptorException
This method computes the MAC message signature for the clear text. This is basically a checksum so you know you decrypted the data successfully and that it wasn't tampered with.

Parameters:
pClearText - the plain text you wish to compute the MAC for. This must match the plain text you encrypt.
Returns:
a String, which is a Base64 encoded version of the checksum signature of the cleartext, based on the current algorithm and key.
Throws:
EncryptorException - if the key is invalid, if the algorithm is improperly defined, or if the encoding fails.

decryptBytes

public byte[] decryptBytes(byte[] pBytesToDecrypt)
                    throws EncryptorException
This method takes in a byte array and decrypts it using the AES algorithm and the key used to setup this class.

Parameters:
pBytesToDecrypt - the byte array to be decrypted using AES and the key in mKeyBytes.
Returns:
a byte array of decrypted data.
Throws:
EncryptorException - if decryption fails.

decryptString

public java.lang.String decryptString(java.lang.String pEncryptedContent)
                               throws EncryptorException
This method takes in a String of a Base64 encoded byte array of encrypted data and decrypts it using the AES algorithm and the key used to setup this class.

Parameters:
pEncryptedContent - the String of encoded and encrypted content which should be decrypted.
Returns:
a byte array of decrypted data.
Throws:
EncryptorException - if decryption fails.

doStartService

public void doStartService()
                    throws atg.nucleus.ServiceException
This method sets up our component, and creates the Encryptor object.

Throws:
atg.nucleus.ServiceException - if key is null
See Also:
GenericService.doStartService()

setupEncryptor

public abstract void setupEncryptor()
                             throws EncryptorException
This method sets up the encryptor. It must be overriden by the actual type of encryptor component you wish to use. An example body would look like this: final byte[] keyBytes = Base64.decodeToByteArray(getKey()); this.mEncryptor = new AbstractEncryptor(keyBytes);

Throws:
EncryptorException - if the encryptor could not be created

encryptBytes

public byte[] encryptBytes(byte[] pBytesToEncrypt)
                    throws EncryptorException
This method takes in a byte array and encrypts it using the AES algorithm and the key used to setup this class.

Parameters:
pBytesToEncrypt - the byte array to be encrypted using AES and the key in mKeyBytes
Returns:
a byte array of encrypted data
Throws:
EncryptorException - if encryption fails.

encryptString

public java.lang.String encryptString(java.lang.String pUnencryptedContent)
                               throws EncryptorException
This method takes in a String and encrypts is using the AES algorithm and the key used to setup this class.

Parameters:
pUnencryptedContent - the String to be encrypted using AES and the key in mKey.
Returns:
a String of Base64 encoded, encrypted bytes.
Throws:
EncryptorException - if encryption fails.

getKey

public java.lang.String getKey()
Returns:
Returns the key.

setKey

public void setKey(java.lang.String pKey)
Parameters:
pKey - The key to set.

getEncryptor

public AbstractEncryptor getEncryptor()
Returns:
the encryptor

setEncryptor

public void setEncryptor(AbstractEncryptor pEncryptor)
Parameters:
pEncryptor - the encryptor to set