Interface Hash

All Superinterfaces:
org.apache.shiro.lang.util.ByteSource
All Known Implementing Classes:
AbstractCryptHash, AbstractHash, Sha256Hash, Sha384Hash, Sha512Hash, SimpleHash

public interface Hash extends org.apache.shiro.lang.util.ByteSource
A Cryptographic Hash represents a one-way conversion algorithm that transforms an input source to an underlying byte array. Hex and Base64-encoding output of the hashed bytes are automatically supported by the inherited toHex() and toBase64() methods.

The bytes returned by the parent interface's getBytes() are the hashed value of the original input source, also known as the 'checksum' or 'digest'.

Since:
0.9
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.apache.shiro.lang.util.ByteSource

    org.apache.shiro.lang.util.ByteSource.Util
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the name of the algorithm used to hash the input source, for example, SHA-256, MD5, etc.
    int
    Returns the number of hash iterations used to compute the hash.
    org.apache.shiro.lang.util.ByteSource
    Returns a salt used to compute the hash or null if no salt was used.
    boolean
    matchesPassword(org.apache.shiro.lang.util.ByteSource plaintextBytes)
    Tests if a given passwords matches with this instance.

    Methods inherited from interface org.apache.shiro.lang.util.ByteSource

    getBytes, isEmpty, toBase64, toHex
  • Method Details

    • getAlgorithmName

      Returns the name of the algorithm used to hash the input source, for example, SHA-256, MD5, etc.

      The name is expected to be a MessageDigest algorithm name.

      Returns:
      the the name of the algorithm used to hash the input source, for example, SHA-256, MD5, etc.
      Since:
      1.1
    • getSalt

      org.apache.shiro.lang.util.ByteSource getSalt()
      Returns a salt used to compute the hash or null if no salt was used.
      Returns:
      a salt used to compute the hash or null if no salt was used.
      Since:
      1.2
    • getIterations

      Returns the number of hash iterations used to compute the hash.
      Returns:
      the number of hash iterations used to compute the hash.
      Since:
      1.2
    • matchesPassword

      boolean matchesPassword(org.apache.shiro.lang.util.ByteSource plaintextBytes)
      Tests if a given passwords matches with this instance.

      Usually implementations will re-create this but with the given plaintext bytes as secret.

      Parameters:
      plaintextBytes - the plaintext bytes from a user.
      Returns:
      true if the given plaintext generates an equal hash with the same parameters as from this hash.