core
Class MessageKey

java.lang.Object
  |
  +--core.Message
        |
        +--core.MessageKey
All Implemented Interfaces:
IMessage, IMessageKey

public class MessageKey
extends Message
implements IMessageKey

This class represents a Message which is a Key. It is useful for protocols in which a Key is sent from one Agent to another.

Author:
Xavier Didelot

Field Summary
 
Fields inherited from class core.Message
 
Constructor Summary
MessageKey()
          Create an empty MessageKey
MessageKey(java.security.Key key)
          Create a MessageKey containing a Key
MessageKey(Message msg)
           
MessageKey(java.lang.String algo)
          Create a new MessageKey containing a fresh key generated with the given algorithm
 
Method Summary
static java.security.Key createKey(java.lang.String algo)
          This static method returns a fresh Key created with the given algorithm
static java.security.Key keyFromFile(java.lang.String file)
          Reads a key from a file
static void main(java.lang.String[] args)
          This sample method shows how to store a Key in a file
static void storeKeyToFile(java.security.Key key, java.lang.String file)
          Store a Key into a File
 java.security.Key toKey()
          Convert this MessageKey into a Key
 
Methods inherited from class core.Message
addMessage, clone, decrypt, encrypt, equals, getAllFields, getString, hash, setString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface core.IMessage
addMessage, decrypt, encrypt, equals, getAllFields, getString, hash, setString
 

Constructor Detail

MessageKey

public MessageKey()
Create an empty MessageKey


MessageKey

public MessageKey(java.lang.String algo)
           throws java.io.IOException,
                  java.security.NoSuchAlgorithmException
Create a new MessageKey containing a fresh key generated with the given algorithm

Parameters:
algo - algorithm to use for generation of the fresh key
Throws:
java.io.IOException
java.security.NoSuchAlgorithmException

MessageKey

public MessageKey(java.security.Key key)
           throws java.io.IOException
Create a MessageKey containing a Key

Parameters:
key - Key that has to be contained in the Message
Throws:
java.io.IOException

MessageKey

public MessageKey(Message msg)
Method Detail

toKey

public java.security.Key toKey()
                        throws java.io.IOException,
                               java.lang.ClassNotFoundException
Convert this MessageKey into a Key

Specified by:
toKey in interface IMessageKey
Returns:
the Key contained in this Message
Throws:
java.io.IOException
java.lang.ClassNotFoundException

keyFromFile

public static java.security.Key keyFromFile(java.lang.String file)
                                     throws java.io.IOException,
                                            java.lang.ClassNotFoundException
Reads a key from a file

Parameters:
file - file where is stored the key
Returns:
Key stored in the file
Throws:
java.io.IOException
java.lang.ClassNotFoundException

storeKeyToFile

public static void storeKeyToFile(java.security.Key key,
                                  java.lang.String file)
                           throws java.io.IOException
Store a Key into a File

Parameters:
key - Key to store in the File
file - file where the Key has to be stored
Throws:
java.io.IOException

createKey

public static java.security.Key createKey(java.lang.String algo)
                                   throws java.security.NoSuchAlgorithmException
This static method returns a fresh Key created with the given algorithm

Parameters:
algo - algoritm to use for creation of a fresh key
Returns:
a fresh key
Throws:
java.security.NoSuchAlgorithmException

main

public static void main(java.lang.String[] args)
This sample method shows how to store a Key in a file

Parameters:
args - the Array args must contain two fields: firstly the algorithm to use to create a fresh Key and secondly the name of the file where to store the generated key