ecash.kernel
Class Tools

java.lang.Object
  |
  +--ecash.kernel.Tools

public class Tools
extends java.lang.Object

This class provides some tools.

Author:
Michel Deriaz

Field Summary
static int HASH_LENGTH
          Defines the length in bits of the result of the hash function.
 
Method Summary
static java.util.Vector notesExpToValues(java.lang.String notesExp)
          Splits a notes expression into a vector of values.
static java.lang.String readFile(java.lang.String filename)
          Returns the content of a file as a String.
static java.lang.Object readObject(java.lang.String filename)
          Reads an object from the specified file.
static double round(double d)
          This method rounds a double by keeping only 2 decimals (centimes).
static double round(java.lang.String s)
          This method rounds a double by keeping only 2 decimals (centimes).
static java.math.BigInteger sha(java.math.BigInteger message)
          Computes a hash of the message, using the SHA function.
static java.math.BigInteger signEnvelope(java.math.BigInteger envelope, KeyRing keyRing)
          Signs an envelope using the private key of the bank.
static java.math.BigInteger unblind(java.math.BigInteger signedEnvelope, FullNotesList fullNotesList, BankChoice bankChoice, PubKey pubKey)
          Unblinds a signed envelope in order to get the signed note.
static java.lang.String valuesToNotesExp(java.util.Vector v)
          Transforms a vector of values (amounts) into a notes expression.
static void writeFile(java.lang.String filename, java.lang.String text)
          Writes a String in a file.
static void writeObject(java.lang.String filename, java.lang.Object object)
          Writes the specified object into the specified file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HASH_LENGTH

public static final int HASH_LENGTH
Defines the length in bits of the result of the hash function. This package uses the sha function, so the value must be 160. This value is important because it is used for exemple when creating a note.

See Also:
Constant Field Values
Method Detail

signEnvelope

public static java.math.BigInteger signEnvelope(java.math.BigInteger envelope,
                                                KeyRing keyRing)
Signs an envelope using the private key of the bank.

Parameters:
envelope - the envelope to sign
Returns:
a signed envelope

unblind

public static java.math.BigInteger unblind(java.math.BigInteger signedEnvelope,
                                           FullNotesList fullNotesList,
                                           BankChoice bankChoice,
                                           PubKey pubKey)
Unblinds a signed envelope in order to get the signed note. This method needs a full notes list and the bank choice to get the blinding factor k.

Parameters:
signedEnvelope - the envelope signed by the bank and containing the wanted note
fullNotesList - the full notes list
bankChoice - the choice of the bank
pubKey - the public key of the bank
Returns:
the note, signed blindfully by the bank

sha

public static java.math.BigInteger sha(java.math.BigInteger message)
Computes a hash of the message, using the SHA function.

Parameters:
message - the message to hash
Returns:
a 160-bit hash of the message

readFile

public static java.lang.String readFile(java.lang.String filename)
Returns the content of a file as a String. The path of this file is specified by the Const.DIR constant.

Parameters:
filename - the filename
Returns:
the content of a file as a String.
See Also:
Const.DIR

writeFile

public static void writeFile(java.lang.String filename,
                             java.lang.String text)
Writes a String in a file. The path of this file is specified by the Const.DIR constant.

Parameters:
filename - the filename
text - the String to write
See Also:
Const.DIR

readObject

public static java.lang.Object readObject(java.lang.String filename)
Reads an object from the specified file.

Parameters:
filename - the filename
Returns:
the object found in the specified file

writeObject

public static void writeObject(java.lang.String filename,
                               java.lang.Object object)
Writes the specified object into the specified file.

Parameters:
filename - the filename
object - the object to save in a file

valuesToNotesExp

public static java.lang.String valuesToNotesExp(java.util.Vector v)
Transforms a vector of values (amounts) into a notes expression. Each item of the vector must be a String and must represent an amount.

Parameters:
v - the vector of amounts
Returns:
the corresponding notes expression
See Also:
notesExpToValues(java.lang.String)

notesExpToValues

public static java.util.Vector notesExpToValues(java.lang.String notesExp)
Splits a notes expression into a vector of values. Each item of this vector is a String and represents an amount.

Parameters:
notesExp - the notes expression to split
Returns:
a vector of values (amounts)
See Also:
valuesToNotesExp(java.util.Vector)

round

public static double round(double d)
This method rounds a double by keeping only 2 decimals (centimes).

Parameters:
d - the double to round
Returns:
a double with maximum 2 decimals

round

public static double round(java.lang.String s)
This method rounds a double by keeping only 2 decimals (centimes).

Parameters:
s - the double to round
Returns:
a double with maximum 2 decimals