edu.ucf.cs.courses.cop4610l.beans.crypto
Class Crypto

java.lang.Object
  |
  +--edu.ucf.cs.courses.cop4610l.beans.crypto.Crypto
All Implemented Interfaces:
java.io.Serializable

public class Crypto
extends java.lang.Object
implements java.io.Serializable

A JavaBean that encapsulates common encryption functions. It takes as an argument an InputStream and returns (via an event) another InputStream that can be consumed by another object.

See Also:
Serialized Form

Field Summary
private static java.lang.String KEY_PASSWORD
          Password for individual keys in the keystore.
private static java.lang.String KEY_PREFIX
          Prefix for all keys created by beans of this type.
private static java.lang.String KEYSTORE_FILENAME
          Filename of the keystore of type "JCEKS" which holds all keys generated by any beans of this type.
private static java.lang.String KEYSTORE_PASSWORD
          Password for keystore in KEYSTORE_FILENAME.
private  java.util.Set listeners
          Listeners of TransformCompletedEvents.
private  java.lang.String symmetricCipherName
          The symmetric algorithm for this bean to use (default is "DES").
private  java.io.InputStream symmetricTransformedStream
          The stream that is consumed by listeners when a TransformCompletedEvent is fired.
 
Constructor Summary
Crypto()
           
 
Method Summary
 void addTransformCompletedListener(TransformCompletedListener listener)
          This bean currently can only support one listener.
 void doSymmetricDecrypt(java.io.InputStream in)
          Decrypts contents of in using the algorithm specified by symmetricCipherName.
 void doSymmetricEncrypt(java.io.InputStream in)
          Encrypts contents of in using the algorithm specified by symmetricCipherName.
private  void doSymmetricTransform(java.io.InputStream in, int cipherMode)
          Used by both doSymmmetricEncrypt and doSymmetricDecrypt.
private  java.security.Key findKey(java.lang.String cipherName)
          This method does the following: Loads keystore if it exists on disk.
private  void fireTransformCompleted(TransformCompletedEvent e)
           
 java.lang.String getSymmetricCipherName()
           
 java.io.InputStream getSymmetricTransformedStream()
          There is only a getter method for this property since it is read-only.
 void removeTransformCompletedListener(TransformCompletedListener listener)
           
 void setSymmetricCipherName(java.lang.String symmetricCipherName)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

symmetricCipherName

private java.lang.String symmetricCipherName
The symmetric algorithm for this bean to use (default is "DES").

KEYSTORE_FILENAME

private static final java.lang.String KEYSTORE_FILENAME
Filename of the keystore of type "JCEKS" which holds all keys generated by any beans of this type.

KEYSTORE_PASSWORD

private static final java.lang.String KEYSTORE_PASSWORD
Password for keystore in KEYSTORE_FILENAME.

KEY_PASSWORD

private static final java.lang.String KEY_PASSWORD
Password for individual keys in the keystore. (All key passwords are the same.)

KEY_PREFIX

private static final java.lang.String KEY_PREFIX
Prefix for all keys created by beans of this type. This allows to bean to only use keys created by it even though others might exist for a given algorithm.

listeners

private java.util.Set listeners
Listeners of TransformCompletedEvents.

symmetricTransformedStream

private java.io.InputStream symmetricTransformedStream
The stream that is consumed by listeners when a TransformCompletedEvent is fired.
Constructor Detail

Crypto

public Crypto()
Method Detail

getSymmetricTransformedStream

public java.io.InputStream getSymmetricTransformedStream()
There is only a getter method for this property since it is read-only. It should be called only after hearing a TransformCompletedEvent.
Returns:
the transformed stream

getSymmetricCipherName

public java.lang.String getSymmetricCipherName()

setSymmetricCipherName

public void setSymmetricCipherName(java.lang.String symmetricCipherName)

doSymmetricEncrypt

public void doSymmetricEncrypt(java.io.InputStream in)
Encrypts contents of in using the algorithm specified by symmetricCipherName. A TransformCompletedEvent is fired when done.
Parameters:
in - the stream to encrypt

doSymmetricDecrypt

public void doSymmetricDecrypt(java.io.InputStream in)
Decrypts contents of in using the algorithm specified by symmetricCipherName. A TransformCompletedEvent is fired when done.
Parameters:
in - the stream to decrypt

findKey

private java.security.Key findKey(java.lang.String cipherName)
                           throws java.lang.Exception
This method does the following: Loads keystore if it exists on disk. Otherwise it creates a new one. If the key with the algorithm given by cipherName exists, it returns it. Otherwise it creates a new key with the given algorithm, stores it in the keystore, then saves the updated keystore.
Parameters:
cipherName - algorithm of key to look for
Returns:
existing key or new one if no existing key

doSymmetricTransform

private void doSymmetricTransform(java.io.InputStream in,
                                  int cipherMode)
Used by both doSymmmetricEncrypt and doSymmetricDecrypt. The only difference between the two methods is the Cipher mode.
Parameters:
in -  
cipherMode -  

addTransformCompletedListener

public void addTransformCompletedListener(TransformCompletedListener listener)
                                   throws java.util.TooManyListenersException
This bean currently can only support one listener.
Parameters:
listener -  
Throws:
java.util.TooManyListenersException - if more than one listener attempts to add

removeTransformCompletedListener

public void removeTransformCompletedListener(TransformCompletedListener listener)

fireTransformCompleted

private void fireTransformCompleted(TransformCompletedEvent e)