Class Shiro2CryptFormat

java.lang.Object
org.apache.shiro.crypto.hash.format.Shiro2CryptFormat
All Implemented Interfaces:
HashFormat, ModularCryptFormat, ParsableHashFormat

The Shiro2CryptFormat is a fully reversible Modular Crypt Format (MCF). It is based on the posix format for storing KDF-hashed passwords in /etc/shadow files on linux and unix-alike systems.

Format

Hash instances formatted with this implementation will result in a String with the following dollar-sign ($) delimited format:

 $mcfFormatId$algorithmName$algorithm-specific-data.
 

Each token is defined as follows:

Position Token Description Required?
1 mcfFormatId The Modular Crypt Format identifier for this implementation, equal to shiro2. ( This implies that all shiro2 MCF-formatted strings will always begin with the prefix $shiro2$ ). true
2 algorithmName The name of the hash algorithm used to perform the hash. Either a hash class exists, or otherwise a UnsupportedOperationException will be thrown. true
3 algorithm-specific-data In contrast to the previous shiro1 format, the shiro2 format does not make any assumptions about how an algorithm stores its data. Therefore, everything beyond the first token is handled over to the Hash implementation.
Since:
2.0
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getId

      public String getId()
      Description copied from interface: ModularCryptFormat
      Returns the Modular Crypt Format identifier that indicates how the formatted String should be parsed. This id is always in the MCF-formatted string's first token.

      Example values are md5, 1, 2, apr1, etc.

      Specified by:
      getId in interface ModularCryptFormat
      Returns:
      the Modular Crypt Format identifier that indicates how the formatted String should be parsed.
    • format

      public String format(Hash hash)
      Converts a Hash-extending class to a string understood by the hash class. Usually this string will follow posix standards for passwords stored in /etc/passwd.

      This method should only delegate to the corresponding formatter and prepend $shiro2$.

      Specified by:
      format in interface HashFormat
      Parameters:
      hash - the hash instance to format into a String.
      Returns:
      a string representing the hash.
    • parse

      public Hash parse(String formatted)
      Description copied from interface: ParsableHashFormat
      Parses the specified formatted string and returns the corresponding Hash instance.
      Specified by:
      parse in interface ParsableHashFormat
      Parameters:
      formatted - the formatted string representing a Hash.
      Returns:
      the corresponding Hash instance.