eneter.messaging.dataprocessing.serializing
Class AesSerializer

java.lang.Object
  extended by eneter.messaging.dataprocessing.serializing.AesSerializer
All Implemented Interfaces:
ISerializer

public class AesSerializer
extends java.lang.Object
implements ISerializer

Serializer using AES (Advanced Encryption Standard). The serializer uses an underlying serializer to serialize and deserialize data. Data encoded by the underlying serializer is then encrypted by AES.

 Encrypted serialization with XmlStringSerializer.
 
// Create the serializer. The defualt constructor uses XmlStringSerializer. AesSerializer aSerializer = new AesSerializer("My password."); // Create some data to be serialized. MyData aData = new MyData(); ... // Serialize data with using AES. object aSerializedData = aSerializer.serialize(aData, MyData.class); ... // Deserialize data MyData aDeserialized = aSerializer.deserialize(aSerializedData, MyData.class);


Constructor Summary
AesSerializer(java.security.Key key, javax.crypto.spec.IvParameterSpec iv, ISerializer underlyingSerializer)
           
AesSerializer(java.lang.String password)
          Constructs the serializer.
AesSerializer(java.lang.String password, byte[] salt)
          Constructs the serializer.
AesSerializer(java.lang.String password, byte[] salt, ISerializer underlyingSerializer)
           
AesSerializer(java.lang.String password, ISerializer underlyingSerializer)
          Constructs the serializer.
 
Method Summary
<T> T
deserialize(java.lang.Object serializedData, java.lang.Class<T> clazz)
          Deserializes data.
<T> java.lang.Object
serialize(T dataToSerialize, java.lang.Class<T> clazz)
          Serializes data.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AesSerializer

public AesSerializer(java.lang.String password)
              throws java.lang.Exception
Constructs the serializer. It uses XmlStringSerializer as the underlying serializer.

Parameters:
password - Password used to generate 128 bit key. The password is transfered to the key with using PBKDF2.
Throws:
java.lang.Exception

AesSerializer

public AesSerializer(java.lang.String password,
                     ISerializer underlyingSerializer)
              throws java.lang.Exception
Constructs the serializer.

Parameters:
password - Password used to generate 128 bit key. The password is transfered to the key with using PBKDF2.
underlyingSerializer - underlying serializer (e.g. XmlStringSerializer or JavaBinarySerializer)
Throws:
java.lang.Exception

AesSerializer

public AesSerializer(java.lang.String password,
                     byte[] salt)
              throws java.lang.Exception
Constructs the serializer.

Parameters:
password - Password used to generate 128 bit key. The password is transfered to the key with using PBKDF2.
salt - additional value used to calculate the key
Throws:
java.lang.Exception

AesSerializer

public AesSerializer(java.lang.String password,
                     byte[] salt,
                     ISerializer underlyingSerializer)
              throws java.lang.Exception
Throws:
java.lang.Exception

AesSerializer

public AesSerializer(java.security.Key key,
                     javax.crypto.spec.IvParameterSpec iv,
                     ISerializer underlyingSerializer)
Method Detail

serialize

public <T> java.lang.Object serialize(T dataToSerialize,
                                      java.lang.Class<T> clazz)
                           throws java.lang.Exception
Description copied from interface: ISerializer
Serializes data.

Specified by:
serialize in interface ISerializer
Parameters:
dataToSerialize - Data to be serialized.
clazz - represents the serialized type.
Returns:
Object representing the serialized data. Based on the serializer implementation it can be byte[] or String.
Throws:
java.lang.Exception - If the serialization fails.

deserialize

public <T> T deserialize(java.lang.Object serializedData,
                         java.lang.Class<T> clazz)
              throws java.lang.Exception
Description copied from interface: ISerializer
Deserializes data.

Specified by:
deserialize in interface ISerializer
Parameters:
serializedData - Data to be deserialized.
Returns:
Deserialized object.
Throws:
java.lang.Exception - If the deserialization fails.