Class Shiro1CryptFormat
java.lang.Object
org.apache.shiro.crypto.hash.format.Shiro1CryptFormat
- All Implemented Interfaces:
HashFormat,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 invalid input: '<'= N invalid input: '<'= 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringshiro1 crypt id.static final Stringshiro1 crypt format prefixFields inherited from interface org.apache.shiro.crypto.hash.format.ModularCryptFormat
TOKEN_DELIMITER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a formatted string representing the specified Hash instance.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
-
Shiro1CryptFormat
public Shiro1CryptFormat()
-
-
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
Description copied from interface:HashFormatReturns a formatted string representing the specified Hash instance.- Specified by:
formatin interfaceHashFormat- Parameters:
hash- the hash instance to format into a String.- Returns:
- a formatted string representing the specified Hash instance.
-
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.
-