atg.projects.store.crypto
Class AbstractEncryptor

java.lang.Object
  extended by atg.projects.store.crypto.AbstractEncryptor
All Implemented Interfaces:
Encryptor, java.io.Serializable
Direct Known Subclasses:
DESedeEncryptor, DESEncryptor

public abstract class AbstractEncryptor
extends java.lang.Object
implements Encryptor, java.io.Serializable

A simple abstract class for performing encryption/decryption.

See Also:
Serialized Form

Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Constructor Summary
AbstractEncryptor()
          Default constructor.
 
Method Summary
 void acceptDecryptKey(byte[] pValue)
          Sets the key property.
 void acceptEncryptKey(byte[] pValue)
          Sets the pValue property.
protected  byte[] decodeToByteArray(java.lang.String pValue)
          Override this method to decode the data back into raw encrypted data if you have used a character encoder.
 byte[] decrypt(byte[] pValue)
          Decrypts encrypted pValue byte[].
 java.lang.String decrypt(java.lang.String pValue)
          Decrypts encrypted pValue string.
protected abstract  void doAcceptDecryptKey(byte[] pValue)
          Implement this to accept a byte array as a key.
protected abstract  void doAcceptEncryptKey(byte[] pValue)
          Implement this to accept a byte array as a key.
protected abstract  byte[] doDecrypt(byte[] pValue)
          Implement this with the actual decryption operation.
protected abstract  byte[] doEncrypt(byte[] pValue)
          Implement this with the actual encryption operation.
protected abstract  void doInit()
          Implement this and do your init.
protected  java.lang.String encodeToString(byte[] pValue)
          Override this method if encoding of the raw encrypted data is necessary.
 byte[] encrypt(byte[] pValue)
          Encrypts pValue byte[].
 java.lang.String encrypt(java.lang.String pValue)
          Encrypts pValue string.
protected  void init()
          Call this init method before every cryptograpy operation.
protected  byte[] postDecrypt(byte[] pValue)
          Process pValue after decrypt.
protected  java.lang.String postDecrypt(java.lang.String pValue)
          Process pValue after decrypt.
protected  byte[] postEncrypt(byte[] pValue)
          Process pValue after encrypt.
protected  java.lang.String postEncrypt(java.lang.String pValue)
          Process pValue after encrypt.
protected  byte[] preDecrypt(byte[] pValue)
          Process pValue before decrypt.
protected  java.lang.String preDecrypt(java.lang.String pValue)
          Process pValue before decrypt.
protected  byte[] preEncrypt(byte[] pValue)
          Process pValue before encrypt.
protected  java.lang.String preEncrypt(java.lang.String pValue)
          Process pValue before encrypt.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

AbstractEncryptor

public AbstractEncryptor()
Default constructor.

Method Detail

acceptEncryptKey

public final void acceptEncryptKey(byte[] pValue)
                            throws EncryptorException
Sets the pValue property. This must get called before any encryption operations take place.

Specified by:
acceptEncryptKey in interface Encryptor
Parameters:
pValue - The byte[] to set as the key property.
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

acceptDecryptKey

public final void acceptDecryptKey(byte[] pValue)
                            throws EncryptorException
Sets the key property. This must get called before any encryption operations take place.

Specified by:
acceptDecryptKey in interface Encryptor
Parameters:
pValue - The byte[] to set as the key property.
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

init

protected final void init()
                   throws EncryptorException
Call this init method before every cryptograpy operation.

Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

encrypt

public final java.lang.String encrypt(java.lang.String pValue)
                               throws EncryptorException
Encrypts pValue string.

Specified by:
encrypt in interface Encryptor
Parameters:
pValue - String to encrypt.
Returns:
Encrypted string.
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

decrypt

public final java.lang.String decrypt(java.lang.String pValue)
                               throws EncryptorException
Decrypts encrypted pValue string.

Specified by:
decrypt in interface Encryptor
Parameters:
pValue - encrypted String
Returns:
decrypted String
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

encrypt

public final byte[] encrypt(byte[] pValue)
                     throws EncryptorException
Encrypts pValue byte[].

Specified by:
encrypt in interface Encryptor
Parameters:
pValue - byte[] array to encrypt.
Returns:
encrypted byte[] array
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

decrypt

public final byte[] decrypt(byte[] pValue)
                     throws EncryptorException
Decrypts encrypted pValue byte[].

Specified by:
decrypt in interface Encryptor
Parameters:
pValue - encrypted array of byte[]
Returns:
decrypted array of byte[]
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

preEncrypt

protected java.lang.String preEncrypt(java.lang.String pValue)
                               throws EncryptorException
Process pValue before encrypt.

Parameters:
pValue - String to encrypt
Returns:
String after processing
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

preDecrypt

protected java.lang.String preDecrypt(java.lang.String pValue)
                               throws EncryptorException
Process pValue before decrypt.

Parameters:
pValue - String to decrypt
Returns:
String after processing
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

postEncrypt

protected java.lang.String postEncrypt(java.lang.String pValue)
                                throws EncryptorException
Process pValue after encrypt.

Parameters:
pValue - String after encryption
Returns:
String after processing
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

postDecrypt

protected java.lang.String postDecrypt(java.lang.String pValue)
                                throws EncryptorException
Process pValue after decrypt.

Parameters:
pValue - String after decryption
Returns:
String after processing
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

preEncrypt

protected byte[] preEncrypt(byte[] pValue)
                     throws EncryptorException
Process pValue before encrypt.

Parameters:
pValue - byte[] to encrypt
Returns:
byte[] after processing
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

preDecrypt

protected byte[] preDecrypt(byte[] pValue)
                     throws EncryptorException
Process pValue before decrypt.

Parameters:
pValue - byte[] to decrypt
Returns:
byte[] after processing
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

postEncrypt

protected byte[] postEncrypt(byte[] pValue)
                      throws EncryptorException
Process pValue after encrypt.

Parameters:
pValue - byte[] after encryption
Returns:
byte[] after processing
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

postDecrypt

protected byte[] postDecrypt(byte[] pValue)
                      throws EncryptorException
Process pValue after decrypt.

Parameters:
pValue - byte[] after decryption
Returns:
byte[] after processing
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

encodeToString

protected java.lang.String encodeToString(byte[] pValue)
                                   throws EncryptorException
Override this method if encoding of the raw encrypted data is necessary. Once encrypted, string data may no longer a string because the encrypted data is binary and may contain null characters, thus it may need to be encoded using a encoder such as Base64, UUEncode (ASCII only) or UCEncode(ASCII independent).

Parameters:
pValue - array of byte[] to encrypt
Returns:
resulted string
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

decodeToByteArray

protected byte[] decodeToByteArray(java.lang.String pValue)
                            throws EncryptorException
Override this method to decode the data back into raw encrypted data if you have used a character encoder.

Parameters:
pValue - string to decode
Returns:
resuled byte[]
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

doAcceptEncryptKey

protected abstract void doAcceptEncryptKey(byte[] pValue)
                                    throws EncryptorException
Implement this to accept a byte array as a key.

Parameters:
pValue - byte array
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

doAcceptDecryptKey

protected abstract void doAcceptDecryptKey(byte[] pValue)
                                    throws EncryptorException
Implement this to accept a byte array as a key.

Parameters:
pValue - byte array
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

doInit

protected abstract void doInit()
                        throws EncryptorException
Implement this and do your init.

Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

doEncrypt

protected abstract byte[] doEncrypt(byte[] pValue)
                             throws EncryptorException
Implement this with the actual encryption operation.

Parameters:
pValue - array of bytes
Returns:
encrypted array of bytes
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.

doDecrypt

protected abstract byte[] doDecrypt(byte[] pValue)
                             throws EncryptorException
Implement this with the actual decryption operation.

Parameters:
pValue - array of bytes
Returns:
decrypted array of bytes
Throws:
EncryptorException - This exception indicates that a severe error occured while performing a cryptograpy operation.