com.metamatrix.common.util.crypto.cipher
Class BasicCryptor

java.lang.Object
  extended by com.metamatrix.common.util.crypto.cipher.BasicCryptor
All Implemented Interfaces:
Cryptor, Decryptor, Encryptor
Direct Known Subclasses:
SymmetricCryptor

public class BasicCryptor
extends java.lang.Object
implements Cryptor

Implementation of Cryptor interface that can perform both encryption and decryption. Instances of this class can be cast to any of the following interfaces: Cryptor, Encryptor, or Decryptor.

Public methods in this class throw only CryptoExceptions.

See Also:
Encryptor, Decryptor

Field Summary
protected  java.lang.String cipherAlgorithm
           
protected  java.security.Key decryptKey
          The key to be used for decryption.
protected  javax.crypto.Cipher encryptCipher
          The Cipher to use for encryption.
 
Constructor Summary
BasicCryptor(java.security.Key encryptKey, java.security.Key decryptKey, java.lang.String algorithm)
           
 
Method Summary
 byte[] decrypt(byte[] ciphertext)
          Decrypt the ciphertext to yield the original cleartext.
 java.lang.String decrypt(java.lang.String ciphertext)
          Decrypt the ciphertext to yield the original cleartext.
 byte[] encrypt(byte[] cleartext)
          Encrypt the cleartext in byte array format.
 java.lang.String encrypt(java.lang.String cleartext)
          Encrypt the cleartext
protected  void initDecryptCipher()
          Initialize the ciphers used for encryption and decryption.
protected  void initEncryptCipher()
          Initialize the cipher used for encryption.
 java.io.Serializable sealObject(java.io.Serializable object)
           
static java.lang.String stripEncryptionPrefix(java.lang.String ciphertext)
           
 java.io.Serializable unsealObject(java.io.Serializable object)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

decryptKey

protected java.security.Key decryptKey
The key to be used for decryption.


encryptCipher

protected javax.crypto.Cipher encryptCipher
The Cipher to use for encryption.


cipherAlgorithm

protected java.lang.String cipherAlgorithm
Constructor Detail

BasicCryptor

public BasicCryptor(java.security.Key encryptKey,
                    java.security.Key decryptKey,
                    java.lang.String algorithm)
             throws CryptoException
Throws:
CryptoException
Method Detail

decrypt

public byte[] decrypt(byte[] ciphertext)
               throws CryptoException
Decrypt the ciphertext to yield the original cleartext.

Specified by:
decrypt in interface Decryptor
Parameters:
ciphertext - The text to be encrypted, in byte form
The - decrypted cleartext, in byte form
Throws:
CryptoException

decrypt

public java.lang.String decrypt(java.lang.String ciphertext)
                         throws CryptoException
Description copied from interface: Decryptor
Decrypt the ciphertext to yield the original cleartext.

Specified by:
decrypt in interface Decryptor
Parameters:
ciphertext - The text to be encrypted
Throws:
CryptoException

stripEncryptionPrefix

public static java.lang.String stripEncryptionPrefix(java.lang.String ciphertext)

initDecryptCipher

protected void initDecryptCipher()
                          throws CryptoException
Initialize the ciphers used for encryption and decryption. The ciphers define the algorithms to be used. They are initialized with the appropriate key to be used in the encryption or decryption operation.

Throws:
CryptoException

unsealObject

public java.io.Serializable unsealObject(java.io.Serializable object)
                                  throws CryptoException
Specified by:
unsealObject in interface Decryptor
Throws:
CryptoException

encrypt

public byte[] encrypt(byte[] cleartext)
               throws CryptoException
Encrypt the cleartext in byte array format.

Specified by:
encrypt in interface Encryptor
Parameters:
cleartext - The text to be encrypted, in byte form
The - encrypted ciphertext, in byte form
Throws:
CryptoException

encrypt

public java.lang.String encrypt(java.lang.String cleartext)
                         throws CryptoException
Description copied from interface: Encryptor
Encrypt the cleartext

Specified by:
encrypt in interface Encryptor
Parameters:
cleartext - The text to be encrypted
Throws:
CryptoException

initEncryptCipher

protected void initEncryptCipher()
                          throws CryptoException
Initialize the cipher used for encryption. The cipher defines the algorithm to be used. It is initialized with the appropriate key to be used in the encryption operation.

Throws:
CryptoException

sealObject

public java.io.Serializable sealObject(java.io.Serializable object)
                                throws CryptoException
Specified by:
sealObject in interface Encryptor
Throws:
CryptoException


Copyright © 2009. All Rights Reserved.