java.lang.Object
com.github.natche.gravatarjavaclient.utils.Hasher

public final class Hasher extends Object
A class used for hashing inputs using certain algorithms.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Hasher
    A shared hasher instance using the SHA256 algorithm.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns whether the provided object equals this object.
    static Hasher
    fromAlgorithm(String algorithm)
    Returns a new Hasher instance using the provided algorithm.
    hash(String input)
    Hashes the provided input using the encapsulated algorithm.
    int
    Returns a hash code of this object.
    Returns a string representation of this object.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • SHA256_HASHER

      public static final Hasher SHA256_HASHER
      A shared hasher instance using the SHA256 algorithm.
  • Method Details

    • fromAlgorithm

      public static Hasher fromAlgorithm(String algorithm)
      Returns a new Hasher instance using the provided algorithm.
      Parameters:
      algorithm - the algorithm
      Returns:
      a new Hasher instance using the provided algorithm
      Throws:
      NullPointerException - if the provided algorithm is null
      IllegalArgumentException - if the provided algorithm is empty
    • hash

      public String hash(String input)
      Hashes the provided input using the encapsulated algorithm. Note: prior to hashing, the input is trimmed and converted to lower case.
      Parameters:
      input - the input to hash
      Returns:
      the hashed input
      Throws:
      NullPointerException - if the provided input is null
    • equals

      public boolean equals(Object o)
      Returns whether the provided object equals this object.
      Overrides:
      equals in class Object
      Parameters:
      o - the other object
      Returns:
      whether the provided object equals this object
    • hashCode

      public int hashCode()
      Returns a hash code of this object.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code of this object
    • toString

      public String toString()
      Returns a string representation of this object.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this object