public class Shiro1CryptFormat extends Object implements ModularCryptFormat, ParsableHashFormat
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.
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 |
ModularCryptFormat
,
ParsableHashFormat
Modifier and Type | Field and Description |
---|---|
static String |
ID |
static String |
MCF_PREFIX |
TOKEN_DELIMITER
Constructor and Description |
---|
Shiro1CryptFormat() |
Modifier and Type | Method and Description |
---|---|
String |
format(Hash hash)
Returns a formatted string representing the specified Hash instance.
|
String |
getId()
Returns the Modular Crypt Format identifier that indicates how the formatted String should be parsed.
|
Hash |
parse(String formatted)
Parses the specified formatted string and returns the corresponding Hash instance.
|
public static final String ID
public static final String MCF_PREFIX
public Shiro1CryptFormat()
public String getId()
ModularCryptFormat
md5
, 1
, 2
, apr1
, etc.getId
in interface ModularCryptFormat
public String format(Hash hash)
HashFormat
format
in interface HashFormat
hash
- the hash instance to format into a String.public Hash parse(String formatted)
ParsableHashFormat
parse
in interface ParsableHashFormat
formatted
- the formatted string representing a Hash.Copyright © 2004–2016 The Apache Software Foundation. All rights reserved.