net.spy.util
Class Digest

java.lang.Object
  extended by net.spy.SpyObject
      extended by net.spy.util.Digest

public class Digest
extends SpyObject

Digest for getting checksums, hashing passwords, stuff like that.


Constructor Summary
Digest()
          Get a new Digest object.
Digest(java.lang.String alg)
          Get a Digest object with the given hash algorithm.
 
Method Summary
 boolean checkPassword(java.lang.String pw, java.lang.String hash)
          Check a plaintext password against a hashed password.
 java.lang.String getHash(java.lang.String word)
          Get a hash for a given String.
protected  java.lang.String getHash(java.lang.String word, byte[] salt)
          Get a hash for a String with a known salt.
 java.lang.String getHashAlg()
          Get the hash type to be used by this password digest thing.
 java.lang.String getSaltFreeHash(java.lang.String s)
          Get a hash for a String with no salt.
 byte[] getSaltFreeHashBytes(java.lang.String s)
          Get the hash for a given string (with no salt).
 void prefixHash(boolean doit)
          If set to true, hashes will be prefixed with the type of hash used.
 
Methods inherited from class net.spy.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Digest

public Digest()
Get a new Digest object.


Digest

public Digest(java.lang.String alg)
Get a Digest object with the given hash algorithm.

Method Detail

getHashAlg

public java.lang.String getHashAlg()
Get the hash type to be used by this password digest thing.


prefixHash

public void prefixHash(boolean doit)
If set to true, hashes will be prefixed with the type of hash used. (i.e. {SHA}, {SSHA}, etc...).

Parameters:
doit - whether or not to prefix the hash

checkPassword

public boolean checkPassword(java.lang.String pw,
                             java.lang.String hash)
Check a plaintext password against a hashed password.


getHash

protected java.lang.String getHash(java.lang.String word,
                                   byte[] salt)
Get a hash for a String with a known salt. This should only be used for verification, don't be stupid and start handing out words with static salts.


getSaltFreeHashBytes

public byte[] getSaltFreeHashBytes(java.lang.String s)
Get the hash for a given string (with no salt).

Parameters:
s - the thing to hash
Returns:
the hash

getSaltFreeHash

public java.lang.String getSaltFreeHash(java.lang.String s)
Get a hash for a String with no salt. This should only be used for checksumming, not passwords.


getHash

public java.lang.String getHash(java.lang.String word)
Get a hash for a given String.



Copyright © 1995-2007 SPY Internetworking. All Rights Reserved.