com.waveset.util
Class EncryptedData

java.lang.Object
  extended bycom.waveset.util.AbstractXmlObject
      extended bycom.waveset.util.EncryptedData
All Implemented Interfaces:
javax.naming.Referenceable, XmlObject

public class EncryptedData
extends AbstractXmlObject

The EncryptedData class is to be used by any object containing data which should be private or encrypted to prevent it from being stored or transmitted in clear text. This includes object attributes such as passwords and answers.


Field Summary
static java.lang.String code_id
           
static java.lang.String XML_ELEMENT
          The name of the XML element that wraps this object.
 
Fields inherited from class com.waveset.util.AbstractXmlObject
_trace
 
Constructor Summary
EncryptedData()
          Constructs an empty EncryptedData object.
EncryptedData(boolean useDefault, java.lang.String data)
           
EncryptedData(org.w3c.dom.Element e)
          XML constructor required by the XmlObject interface.
EncryptedData(java.lang.String data)
          Constructs a EncryptedData object with data.
EncryptedData(java.lang.String cipher, java.lang.String data)
           
 
Method Summary
 void clear()
           
 byte[] decrypt()
           
 char[] decryptToCharArray()
           
 java.lang.String decryptToString()
           
 boolean equals(EncryptedData data)
          Temporary so I don't have to rebuild the world.
 boolean equals(java.lang.Object other)
          Compare two EncryptedData objects by first decrypting the data to bytes since the data very well could have been encrypted by different keys.
 void fromString(java.lang.String estring)
          Loads an EncryptedData object with data.
 byte[] getData()
           
 java.lang.String getElementName()
          Return the desired XML element name, required by the XmlObject interface.
 int getPadLen()
           
 int length()
           
 void setData(byte[] data)
           
static void setKey(byte[] key)
          Only ServerKeyStore should call this.
static void setKeyEncryptionKey(byte[] keyEncryptionKey)
          Set the current key-encryption key.
 void setPadLen(int padlen)
           
 java.lang.String toString()
           
 void toXml(java.lang.StringBuffer b, int indent)
          Generate the XML rendering of the encrypted data, required by the XmlObject interface.
 
Methods inherited from class com.waveset.util.AbstractXmlObject
addXmlHeader, cloneObject, dump, dumpFile, getReference, println, setTrace, toIdentityString, toVerboseString, toVerboseString, toXml, toXml, toXml
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

XML_ELEMENT

public static final java.lang.String XML_ELEMENT
The name of the XML element that wraps this object. If you change this, change it in XmlObjectFactory.java

See Also:
Constant Field Values
Constructor Detail

EncryptedData

public EncryptedData()
Constructs an empty EncryptedData object.

Typically used to decrypt an encrypted and base-64-encoded string subsequently specified by fromString(String):


   EncryptedData ed = new EncryptedData();
   ed.fromString(encryptedEncodedString);
   String clearText = ed.decryptToString();

Throws:
java.lang.IllegalStateException - if there is a problem initializing the wrapped Encryptor object.

EncryptedData

public EncryptedData(java.lang.String cipher,
                     java.lang.String data)

EncryptedData

public EncryptedData(boolean useDefault,
                     java.lang.String data)

EncryptedData

public EncryptedData(java.lang.String data)
Constructs a EncryptedData object with data.

Parameters:
data - a clear-text string to be encrypted.

Typically used to encrypt and base-64-encode the string.


   EncryptedData ed = new EncryptedData(clearText);
   String encryptedEncodedString = ed.toString();

Throws:
java.lang.IllegalStateException - if there is a problem initializing the wrapped Encryptor object or if there is a problem encrypting the specified string.

EncryptedData

public EncryptedData(org.w3c.dom.Element e)
              throws WavesetException
XML constructor required by the XmlObject interface.

Method Detail

setKey

public static void setKey(byte[] key)
Only ServerKeyStore should call this.


setKeyEncryptionKey

public static void setKeyEncryptionKey(byte[] keyEncryptionKey)
Set the current key-encryption key. Only com.waveset.security.authn.ServerKeyStore should call this.


getElementName

public java.lang.String getElementName()
Return the desired XML element name, required by the XmlObject interface.

Specified by:
getElementName in interface XmlObject
Specified by:
getElementName in class AbstractXmlObject

decryptToCharArray

public char[] decryptToCharArray()

decryptToString

public java.lang.String decryptToString()

decrypt

public byte[] decrypt()
               throws java.lang.IllegalStateException
Throws:
java.lang.IllegalStateException

getData

public byte[] getData()

setData

public void setData(byte[] data)

clear

public void clear()

equals

public boolean equals(java.lang.Object other)
Compare two EncryptedData objects by first decrypting the data to bytes since the data very well could have been encrypted by different keys.

jsl - this was originally written to take an EncryptedData argument but I had problems with that overloading the inherited Object.equals method when comparing two Objects. Now taking an Object and testing the class. We could in theory now compare with Strings.


equals

public boolean equals(EncryptedData data)
Temporary so I don't have to rebuild the world.


toString

public java.lang.String toString()

fromString

public void fromString(java.lang.String estring)
                throws WavesetException
Loads an EncryptedData object with data.

Parameters:
estring - an encrypted and base-64-encoded string.

Typically used to decrypt an encrypted and base-64-encoded string.


   EncryptedData ed = new EncryptedData();
   ed.fromString(encryptedEncodedString);
   String clearText = ed.decryptToString();

Throws:
WavesetException - if the specified string is not base-64-encoded.

getPadLen

public int getPadLen()

setPadLen

public void setPadLen(int padlen)

length

public int length()

toXml

public void toXml(java.lang.StringBuffer b,
                  int indent)
Generate the XML rendering of the encrypted data, required by the XmlObject interface.

Specified by:
toXml in interface XmlObject
Specified by:
toXml in class AbstractXmlObject