core
Class Message

java.lang.Object
  |
  +--core.Message
All Implemented Interfaces:
IMessage
Direct Known Subclasses:
MessageKey, MessageT, Nonce

public class Message
extends java.lang.Object
implements IMessage

This class represents a Message

Author:
Xavier Didelot

Field Summary
private  java.lang.String string
          This string represents the content of the message
 
Constructor Summary
Message()
          Creates a new empty message
Message(Agent agent)
          Creates a new message containing the given string It is advised to only use Base64 string in the message to avoid any issue
Message(INonce nonce)
           
Message(Message m1, Message m2)
          Creates a new message containing the two given Messages contatenated
 
Method Summary
 void addMessage(Message msg)
          This method concats two messages and put an 'at' symbol between them so that we can divide it later with the method getAllFields for example This means that a Message should never contain the symbol 'at' It is advised to only use Base64 string in the message to avoid any issue
protected  java.lang.Object clone()
          Creates a copy of the Message
 void decrypt(java.lang.String algorithm, java.security.Key key)
          Decrypt the message with a given key, using the given algorithm.
 void encrypt(java.lang.String algorithm, java.security.Key key)
          Encrypts the message with the given key, using the given algorithm, and put the result in Base64 format
 boolean equals(Message other)
          Check if the Message is equal to another one
 IMessage[] getAllFields()
          Returns an array containing the different parts of a message, ie the different messages that have been concatenated in order to build this message
private  Message getField(int field)
          Returns a given part of the message This method should not be used directly, cf getAllFields instead
private  int getNbFields()
          This method tells how many submessages a message contain This method should not be used directly, cf getAllFields
 java.lang.String getString()
          This method returns the value of the protected member string It is especially useful to send a message to another host
 void hash()
          This method hashes the Message
 void setString(java.lang.String string)
          Change the value of the private member string into the given string It is advised to only use Base64 string in the message to avoid any issue
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

string

private java.lang.String string
This string represents the content of the message

Constructor Detail

Message

public Message()
Creates a new empty message


Message

public Message(Agent agent)
Creates a new message containing the given string It is advised to only use Base64 string in the message to avoid any issue


Message

public Message(INonce nonce)

Message

public Message(Message m1,
               Message m2)
Creates a new message containing the two given Messages contatenated

Parameters:
m1 - first message
m2 - second message
Method Detail

getString

public java.lang.String getString()
This method returns the value of the protected member string It is especially useful to send a message to another host

Specified by:
getString in interface IMessage
Returns:
the content of the message

setString

public void setString(java.lang.String string)
Change the value of the private member string into the given string It is advised to only use Base64 string in the message to avoid any issue

Specified by:
setString in interface IMessage
Parameters:
string - new value for the content of the message

addMessage

public void addMessage(Message msg)
This method concats two messages and put an 'at' symbol between them so that we can divide it later with the method getAllFields for example This means that a Message should never contain the symbol 'at' It is advised to only use Base64 string in the message to avoid any issue

Specified by:
addMessage in interface IMessage
Parameters:
msg -

getNbFields

private int getNbFields()
This method tells how many submessages a message contain This method should not be used directly, cf getAllFields

Returns:
the number of messages that have been concatenated in order to create this message

getField

private Message getField(int field)
                  throws java.lang.Exception
Returns a given part of the message This method should not be used directly, cf getAllFields instead

Parameters:
field - number of the field to get
Returns:
the selected part of a message
Throws:
java.lang.Exception - if the message does not contain the part that has been asked for

getAllFields

public IMessage[] getAllFields()
Returns an array containing the different parts of a message, ie the different messages that have been concatenated in order to build this message

Specified by:
getAllFields in interface IMessage
Returns:
an array containing the different parts of a message

encrypt

public void encrypt(java.lang.String algorithm,
                    java.security.Key key)
             throws java.lang.Exception
Encrypts the message with the given key, using the given algorithm, and put the result in Base64 format

Specified by:
encrypt in interface IMessage
Parameters:
algorithm - algorithm to use for encryption
key - key to use for encryption
Throws:
java.lang.Exception

decrypt

public void decrypt(java.lang.String algorithm,
                    java.security.Key key)
             throws java.lang.Exception
Decrypt the message with a given key, using the given algorithm. The message has to be in Base64 format.

Specified by:
decrypt in interface IMessage
Parameters:
algorithm - algorithm to use for decryption
key - key to use for decryption
Throws:
java.lang.Exception

hash

public void hash()
          throws java.security.NoSuchAlgorithmException
This method hashes the Message

Specified by:
hash in interface IMessage
Throws:
java.security.NoSuchAlgorithmException

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
Creates a copy of the Message

Overrides:
clone in class java.lang.Object
java.lang.CloneNotSupportedException
See Also:
Object.clone()

equals

public boolean equals(Message other)
Check if the Message is equal to another one

Specified by:
equals in interface IMessage
Parameters:
other - the other Message
Returns:
true if the messages are the same, false otherwise