Class Shiro1CryptFormat
- java.lang.Object
-
- org.apache.shiro.crypto.hash.format.Shiro1CryptFormat
-
- All Implemented Interfaces:
HashFormat,ModularCryptFormat,ParsableHashFormat
public class Shiro1CryptFormat extends Object implements ModularCryptFormat, ParsableHashFormat
TheShiro1CryptFormatis 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 mcfFormatIdThe Modular Crypt Format identifier for this implementation, equal to shiro1. ( This implies that allshiro1MCF-formatted strings will always begin with the prefix$shiro1$).true 2 algorithmNameThe name of the hash algorithm used to perform the hash. This is an algorithm name understood by MessageDigest.getInstance, for exampleMD5,SHA-256,SHA-256, etc.true 3 iterationCountThe number of hash iterations performed. true (1 <= N <= Integer.MAX_VALUE) 4 base64EncodedSaltThe Base64-encoded salt byte array. This token only exists if a salt was used to perform the hash. false 5 base64EncodedDigestThe Base64-encoded digest byte array. This is the actual hash result. true - Since:
- 1.2
- See Also:
ModularCryptFormat,ParsableHashFormat
-
-
Field Summary
Fields Modifier and Type Field Description static StringIDstatic StringMCF_PREFIX-
Fields inherited from interface org.apache.shiro.crypto.hash.format.ModularCryptFormat
TOKEN_DELIMITER
-
-
Constructor Summary
Constructors Constructor Description Shiro1CryptFormat()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringformat(Hash hash)Returns a formatted string representing the specified Hash instance.StringgetId()Returns the Modular Crypt Format identifier that indicates how the formatted String should be parsed.Hashparse(String formatted)Parses the specified formatted string and returns the corresponding Hash instance.
-
-
-
Field Detail
-
ID
public static final String ID
- See Also:
- Constant Field Values
-
MCF_PREFIX
public static final String MCF_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
getId
public String 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
public String format(Hash hash)
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
public Hash parse(String formatted)
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.
-
-