at.ac.tuwien.infosys.rnue.interfaces
Interface ICryptography


public interface ICryptography

The ICryptography interface specifies the methods necessary for the key handling as well as to sign and verify messages.

A class implementing the ICryptography interface should provide a constructor taking no parameters. In the constructor get a Signature object with the MD5withRSA algorithm. Throw a ShareMeException if it could not get a signature object.


Method Summary
 byte[] convertSerializableToByteArray(java.io.Serializable obj)
          Convert/Serialize an object into a byte array.
 java.security.PublicKey initialize(java.lang.String owner, java.lang.String keyFile)
          Read the key pair from keyFile.
 byte[] sign(java.io.Serializable obj)
          Return the signature of the object obj.
 boolean verify(java.io.Serializable obj, byte[] signature, java.security.PublicKey pubKey)
          Verify the signature of a given object.
 

Method Detail

initialize

public java.security.PublicKey initialize(java.lang.String owner,
                                          java.lang.String keyFile)
                                   throws ShareMeException
Read the key pair from keyFile. If keyFile does not exist, create a new key pair.

Parameters:
owner - the owner of the key pair (can be ignored)
keyFile - the file to read the key pair from.
Returns:
null if the key pair is read from keyFile; the public key otherwise.
Throws:
ShareMeException - If it an error occurs while reading the key pair from file.

sign

public byte[] sign(java.io.Serializable obj)
            throws ShareMeException
Return the signature of the object obj.

Parameters:
obj - the object to create the signature of.
Returns:
byte array representing the signature.
Throws:
ShareMeException - If it could not sign the object.

verify

public boolean verify(java.io.Serializable obj,
                      byte[] signature,
                      java.security.PublicKey pubKey)
               throws ShareMeException
Verify the signature of a given object.

Parameters:
obj - the object whose signature has to be verified
signature - the signature to verify
pubKey - the public key of the person who has signed the object
Returns:
true if the object has been signed by the private key corresponding to the given public key.
Throws:
ShareMeException - If an error occured while verifying.

convertSerializableToByteArray

public byte[] convertSerializableToByteArray(java.io.Serializable obj)
                                      throws ShareMeException
Convert/Serialize an object into a byte array.

Parameters:
obj - the object to be serialized
Returns:
the object's serialized representation.
Throws:
ShareMeException - If an error occurs during the serialization.