Package org.apache.shiro.crypto.hash
Class DefaultHashService
java.lang.Object
org.apache.shiro.crypto.hash.DefaultHashService
- All Implemented Interfaces:
ConfigurableHashService,HashService
Default implementation of the
HashService interface, supporting a customizable hash algorithm name.
Hash Algorithm
You may specify a hash algorithm via thesetDefaultAlgorithmName(String) property. Any algorithm name
understood by the JDK
MessageDigest.getInstance(String algorithmName) method
will work, or any Hash algorithm implemented by any loadable HashSpi. The default is argon2.
A hash and the salt used to compute it are often stored together. If an attacker is ever able to access
the hash (e.g. during password cracking) and it has the full salt value, the attacker has all of the input necessary
to try to brute-force crack the hash (source + complete salt).
However, if part of the salt is not available to the attacker (because it is not stored with the hash), it is
much harder to crack the hash value since the attacker does not have the complete inputs necessary.
- Since:
- 1.2
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newDefaultHashServiceinstance with the following defaults:hashAlgorithmName=SHA-512 -
Method Summary
Modifier and TypeMethodDescriptioncomputeHash(HashRequest request) Computes and responds with a hash based on the specified request.protected StringgetAlgorithmName(HashRequest request) voidSets the name of the key derivation function algorithm that will be used to compute secure hashes for passwords.
-
Constructor Details
-
DefaultHashService
public DefaultHashService()Constructs a newDefaultHashServiceinstance with the following defaults:hashAlgorithmName=SHA-512
-
-
Method Details
-
computeHash
Computes and responds with a hash based on the specified request. This implementation functions as follows:- If the request's
saltis null: A salt will be generated and used to compute the hash. The salt is generated as follows:- Use the combined value as the salt used during hash computation
- Specified by:
computeHashin interfaceHashService- Parameters:
request- the request to process- Returns:
- the response containing the result of the hash computation, as well as any hash salt used that should be exposed to the caller.
- See Also:
- If the request's
-
getAlgorithmName
-
setDefaultAlgorithmName
Description copied from interface:ConfigurableHashServiceSets the name of the key derivation function algorithm that will be used to compute secure hashes for passwords.- Specified by:
setDefaultAlgorithmNamein interfaceConfigurableHashService- Parameters:
name- the name of the key derivation function algorithm that will be used to compute secure hashes for passwords.
-
getDefaultAlgorithmName
-