org.logi.crypto.sign
Class Fingerprint

java.lang.Object
  |
  +--org.logi.crypto.Crypto
        |
        +--org.logi.crypto.sign.Fingerprint
Direct Known Subclasses:
BlindFingerprint

public class Fingerprint
extends Crypto

This class is used to hold a fingerprint of a particular data buffer.

The idea is to calculate a fingerprint in such a way that it is difficult to create a buffer that gives a particular fingerprint. If that buffer also has to match some other criteria, such as being a valid text file in a particular language, then it becomes next to impossible.

All this depends on the hash function used to create the fingerprint being a good one. Fingerprints are created by the various subclasses of HashState, so you should look there for information about a particular hash function.

The CDS for a Fingerprint object is Fingerprint(name,fp) where name is the name of the hash function used and fp the actual fingerprint.

Version:
1.1.0
Author:
Logi Ragnarsson (logir@logi.org)
See Also:
HashState, Signature

Fields inherited from class org.logi.crypto.Crypto
BIT, cdsPath, EMPTY_ARRAY, FOUR, keySource, NIBBLE, ONE, primeCertainty, random, TWO, ZERO
 
Constructor Summary
Fingerprint(java.lang.String hashFunc, byte[] fp)
          Creates a new Fingerprint object.
Fingerprint(java.lang.String hashFunc, byte[] fp, int offset, int n)
          Creates a new Fingerprint object.
 
Method Summary
static Fingerprint create(byte[] buf, int offset, int length, java.lang.String hashFunc)
          Create a Fingerprint object.
static Fingerprint create(byte[] buf, java.lang.String hashFunc)
          Create a Fingerprint object.
static Fingerprint create(java.lang.String s, java.lang.String hashFunc)
          Create a Fingerprint object.
 boolean equals(java.lang.Object obj)
          Test for equality with another object.
 byte[] getBytes()
          Return an array of the bytes in the fingerprint.
 java.lang.String getHashFunc()
          Return the name of the hash function used for this fingerprint.
 int hashCode()
          Return a hash-code based on the bytes of the fingerprint and the hash function name.
static Fingerprint parseCDS(java.lang.String[] param)
          Used by Crypto.fromString when parsing a CDS.
 void prettyPrint(java.io.PrintWriter out, int ind, int rec)
          Print this object to out, indented with ind tabs, going down at most rec levels of recursion.
 java.lang.String toString()
          Return a CDS for this fingerprint.
 
Methods inherited from class org.logi.crypto.Crypto
binString, binString, ensureArrayLength, ensureArrayLength, equal, equalRelaxed, equalSub, fromHexNibble, fromHexString, fromString, fromString, hexString, hexString, hexString, hexString, hexString, initRandom, initRandom, makeClass, makeInt, makeLong, makeSessionKey, pastSpace, pickBits, pickBits, prettyPrint, readBlock, readInt, trimArrayLength, trimArrayLength, trimLeadingZeroes, writeBytes, writeBytes, writeInt
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Fingerprint

public Fingerprint(java.lang.String hashFunc,
                   byte[] fp,
                   int offset,
                   int n)
Creates a new Fingerprint object. It contains the hash value from fp[offset..offset+n-1] which was generated with the named hash function.

Fingerprint

public Fingerprint(java.lang.String hashFunc,
                   byte[] fp)
Creates a new Fingerprint object. It contains the hash value from fp which was generated with the named hash function.
Method Detail

create

public static Fingerprint create(byte[] buf,
                                 int offset,
                                 int length,
                                 java.lang.String hashFunc)
                          throws InvalidCDSException
Create a Fingerprint object. It will contain a fingerprint for the data in buf[offset..offset+length-1] calculated with the named fingerprint hash function.
Throws:
InvalidCDSException - if a HashState object for the named hash function could not be created.

create

public static Fingerprint create(byte[] buf,
                                 java.lang.String hashFunc)
                          throws InvalidCDSException
Create a Fingerprint object. It will contain a fingerprint for the data in buf calculated with the named fingerprint hash function.
Throws:
InvalidCDSException - if a HashState object for the named hash function could not be created.

create

public static Fingerprint create(java.lang.String s,
                                 java.lang.String hashFunc)
                          throws InvalidCDSException
Create a Fingerprint object. It will contain a fingerprint for the string s calculated with the named fingerprint hash function.
Throws:
InvalidCDSException - if a HashState object for the named hash function could not be created.

parseCDS

public static Fingerprint parseCDS(java.lang.String[] param)
                            throws InvalidCDSException
Used by Crypto.fromString when parsing a CDS.

A valid CDS can be created by calling the toString() method.

Throws:
InvalidCDSException - if the CDS is malformed.
See Also:
Crypto.fromString(String)

getHashFunc

public java.lang.String getHashFunc()
Return the name of the hash function used for this fingerprint.

getBytes

public byte[] getBytes()
Return an array of the bytes in the fingerprint.

equals

public boolean equals(java.lang.Object obj)
Test for equality with another object. Returns true if obj is a Fingerprint equal to this.
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Return a hash-code based on the bytes of the fingerprint and the hash function name.
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Return a CDS for this fingerprint.
Overrides:
toString in class java.lang.Object

prettyPrint

public void prettyPrint(java.io.PrintWriter out,
                        int ind,
                        int rec)
                 throws java.io.IOException
Print this object to out, indented with ind tabs, going down at most rec levels of recursion.
Overrides:
prettyPrint in class Crypto


Copyright (c) 1997-2001 Logi Ragnarsson - Distributed under the GPL