something like:
Signature dsa = Signature.getInstance("SHA/DSA");
PrivateKey priv = pair.getPrivate();
dsa.initSign(priv);
He just needs a digest, not a digitally signed digest, doesn't he?
See
http://mindprod.com/jgloss/digest.html
http://mindprod.com/jgloss/md5.html
http://mindprod.com/jgloss/sha1.html
http://mindprod.com/jgloss/adler.html
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* Test MD5 digest computation
*
* @author Roedy Green
* @version 1.0
* @since 2004-06-07
*/
public class MD5
{
/**
* test MD5 digest, requires Java 1.4+
*
* @param args not used
*/
public static void main ( String[] args ) throws
UnsupportedEncodingException, NoSuchAlgorithmException
{
byte[] theTextToDigestAsBytes = "The quick brown fox jumped over
the lazy dog's back".getBytes( "8859_1" /* encoding */ );
MessageDigest md = MessageDigest.getInstance( "MD5" );
md.update( theTextToDigestAsBytes );
byte[] digest = md.digest();
System.out.println( digest.length );
// 16 bytes, 128 bits long
}
}
..
I think Adler should suffice. It is quick and generates 32 bits, all
you need for a hashCode.
// generate an 32-bit Adler checksum/digest
import java.io.UnsupportedEncodingException;
import java.util.zip.Adler32;
public class Adler
{
/**
* test Adler digest
* @param args not used
*/
public static void main ( String[] args ) throws
UnsupportedEncodingException
{
byte[] theTextToDigestAsBytes = "The quick brown fox jumped over
the lazy dog's back".getBytes( "8859_1" /* encoding */ );
Adler32 digester = new Adler32();
digester.update( theTextToDigestAsBytes );
// getValue produces a long to conform to the Checksum
interface.
// Actual result is 32 bits long not 64!
int digest = (int) digester.getValue();
System.out.println( Integer.toHexString( digest ) );
}
}