Class HashFunction

java.lang.Object
eu.webtoolkit.jwt.auth.HashFunction
Direct Known Subclasses:
BCryptHashFunction, MD5HashFunction

public abstract class HashFunction
extends java.lang.Object
An abstract cryptographic hash function interface.

A cryptographic hash function computes a hash value from a message, for which it is hard to guess another message that generates the same hash.

These hash functions are intended for short messages, typically passwords or random tokens, and thus not suitable for computing the hash value of a large document.

When used for passwords, to avoid dictionary attacks, the hash functions accept also a random salt which is hashed together with the password. Not all hash functions are adequate for passwords hashes.

  • Constructor Summary

    Constructors 
    Constructor Description
    HashFunction()  
  • Method Summary

    Modifier and Type Method Description
    abstract java.lang.String compute​(java.lang.String msg, java.lang.String salt)
    Computes the hash of a message + salt.
    abstract java.lang.String getName()
    Returns the name for this hash function.
    boolean verify​(java.lang.String msg, java.lang.String salt, java.lang.String hash)
    Verifies a message with the salted hash.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getName

      public abstract java.lang.String getName()
      Returns the name for this hash function.

      This should return a (short) name that uniquely identifies this hash function.

    • compute

      public abstract java.lang.String compute​(java.lang.String msg, java.lang.String salt)
      Computes the hash of a message + salt.

      The message is usually an ASCII or UTF-8 string.

      The salt and the computed hash are encoded in printable characters. This is usually ASCII-encoded or could be Base64-encoded.

    • verify

      public boolean verify​(java.lang.String msg, java.lang.String salt, java.lang.String hash)
      Verifies a message with the salted hash.

      The base implementation will recompute the hash of the message with the given salt, and compare it to the hash.

      Some methods however store the salt and additional settings in the hash, and this information is thus needed to verify the message hash.