org.logi.crypto.hash
Class Fingerprint

java.lang.Object
  |
  +--org.logi.crypto.Crypto
        |
        +--org.logi.crypto.hash.Fingerprint

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 algorithm used and fp the actual fingerprint.

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 algorithm, 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 algorithm)
          Create a Fingerprint object.
static Fingerprint create(byte[] buf, java.lang.String algorithm)
          Create a Fingerprint object.
static Fingerprint create(java.lang.String s, java.lang.String algorithm)
          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 getName()
          Return the name of the algorithm used for this fingerprint.
 int hashCode()
          Return a hash-code based on the bytes of the fingerprint and the algorithm name.
static Fingerprint parseCDS(java.lang.String arg)
          If "Fingerprint( key )" is a valid CDS for a Fingerprint, then Fingerprint.parseCDS(key) will return the described Fingerprint object.
 java.lang.String toString()
          Return a CDS for this fingerprint.
 
Methods inherited from class org.logi.crypto.Crypto
binString, binString, equal, equalRelaxed, equalSub, fromHexNibble, fromHexString, fromString, fromString, hexString, hexString, hexString, hexString, hexString, initRandom, initRandom, makeClass, makeInt, makeLong, makeSessionKey, pastSpace, pickBits, pickBits, readBlock, readInt, writeBytes, writeBytes, writeInt
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Fingerprint

public Fingerprint(java.lang.String algorithm,
                   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 algorithm.
Method Detail

create

public static Fingerprint create(byte[] buf,
                                 int offset,
                                 int length,
                                 java.lang.String algorithm)
                          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 algorithm.
Throws:
InvalidCDSException - if a HashState object for the named algorithm could not be created.

create

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

create

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

parseCDS

public static Fingerprint parseCDS(java.lang.String arg)
                            throws InvalidCDSException
If "Fingerprint( key )" is a valid CDS for a Fingerprint, then Fingerprint.parseCDS(key) will return the described Fingerprint object.

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

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

getName

public java.lang.String getName()
Return the name of the algorithm 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 algorithm 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


Copyright 1997-2000 Logi Ragnarsson