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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringIdentifier for the shiro2 crypt format.static final StringEnclosed identifier of the shiro2 crypt format.Fields inherited from interface org.apache.shiro.crypto.hash.format.ModularCryptFormat
TOKEN_DELIMITER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConverts a Hash-extending class to a string understood by the hash class.getId()Returns the Modular Crypt Format identifier that indicates how the formatted String should be parsed.Parses the specified formatted string and returns the corresponding Hash instance.
-
Field Details
-
ID
-
MCF_PREFIX
-
-
Constructor Details
-
Shiro2CryptFormat
public Shiro2CryptFormat()
-
-
Method Details
-
getId
Description copied from interface:ModularCryptFormatReturns 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 aremd5,1,2,apr1, etc.- Specified by:
getIdin interfaceModularCryptFormat- Returns:
- the Modular Crypt Format identifier that indicates how the formatted String should be parsed.
-
format
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:
formatin interfaceHashFormat- Parameters:
hash- the hash instance to format into a String.- Returns:
- a string representing the hash.
-
parse
Description copied from interface:ParsableHashFormatParses the specified formatted string and returns the corresponding Hash instance.- Specified by:
parsein interfaceParsableHashFormat- Parameters:
formatted- the formatted string representing a Hash.- Returns:
- the corresponding Hash instance.
-