Class Shiro1CryptFormat

  • All Implemented Interfaces:
    HashFormat, ModularCryptFormat, ParsableHashFormat

    public class Shiro1CryptFormat
    extends Object
    implements ModularCryptFormat, ParsableHashFormat
    The Shiro1CryptFormat is a fully reversible Modular Crypt Format (MCF). Because it is fully reversible (i.e. Hash -> String, String -> Hash), it does NOT use the traditional MCF encoding alphabet (the traditional MCF encoding, aka H64, is bit-destructive and cannot be reversed). Instead, it uses fully reversible Base64 encoding for the Hash digest and any salt value.

    Format

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

     $mcfFormatId$algorithmName$iterationCount$base64EncodedSalt$base64EncodedDigest
     

    Each token is defined as follows:

    Position Token Description Required?
    1 mcfFormatId The Modular Crypt Format identifier for this implementation, equal to shiro1. ( This implies that all shiro1 MCF-formatted strings will always begin with the prefix $shiro1$ ). true
    2 algorithmName The name of the hash algorithm used to perform the hash. This is an algorithm name understood by MessageDigest.getInstance, for example MD5, SHA-256, SHA-256, etc. true
    3 iterationCount The number of hash iterations performed. true (1 <= N <= Integer.MAX_VALUE)
    4 base64EncodedSalt The Base64-encoded salt byte array. This token only exists if a salt was used to perform the hash. false
    5 base64EncodedDigest The Base64-encoded digest byte array. This is the actual hash result. true
    Since:
    1.2
    See Also:
    ModularCryptFormat, ParsableHashFormat
    • Method Detail

      • 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)
        Description copied from interface: HashFormat
        Returns a formatted string representing the specified Hash instance.
        Specified by:
        format in interface HashFormat
        Parameters:
        hash - the hash instance to format into a String.
        Returns:
        a formatted string representing the specified Hash instance.
      • 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.