Package org.apache.shiro.crypto.hash
Class SimpleHashRequest
- java.lang.Object
-
- org.apache.shiro.crypto.hash.SimpleHashRequest
-
- All Implemented Interfaces:
HashRequest
public class SimpleHashRequest extends Object implements HashRequest
Simple implementation ofHashRequestthat can be used when interacting with aHashService.- Since:
- 1.2
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.shiro.crypto.hash.HashRequest
HashRequest.Builder
-
-
Constructor Summary
Constructors Constructor Description SimpleHashRequest(String algorithmName, org.apache.shiro.util.ByteSource source, org.apache.shiro.util.ByteSource salt, int iterations)Creates a new SimpleHashRequest instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetAlgorithmName()Returns the name of the hash algorithm theHashServiceshould use when computing theHash, ornullif the default algorithm configuration of theHashServiceshould be used.intgetIterations()Returns the number of requested hash iterations to be performed when computing the finalHashresult.org.apache.shiro.util.ByteSourcegetSalt()Returns a salt to be used by theHashServiceduring hash computation, ornullif no salt is provided as part of the request.org.apache.shiro.util.ByteSourcegetSource()Returns the source data that will be hashed by aHashService.
-
-
-
Constructor Detail
-
SimpleHashRequest
public SimpleHashRequest(String algorithmName, org.apache.shiro.util.ByteSource source, org.apache.shiro.util.ByteSource salt, int iterations)
Creates a new SimpleHashRequest instance.- Parameters:
algorithmName- the name of the hash algorithm to use. This is often null as theHashServiceimplementation is usually configured with an appropriate algorithm name, but this can be non-null if the hash service's algorithm should be overridden with a specific one for the duration of the request.source- the source to be hashedsalt- any public salt which should be used when computing the hashiterations- the number of hash iterations to execute. Zero (0) indicates no iterations were specified for the request, at which point the number of iterations is decided by theHashService- Throws:
NullPointerException- ifsourceis null or empty.
-
-
Method Detail
-
getSource
public org.apache.shiro.util.ByteSource getSource()
Description copied from interface:HashRequestReturns the source data that will be hashed by aHashService. For example, this might be aByteSourcerepresentation of a password, or file, etc.- Specified by:
getSourcein interfaceHashRequest- Returns:
- the source data that will be hashed by a
HashService.
-
getSalt
public org.apache.shiro.util.ByteSource getSalt()
Description copied from interface:HashRequestReturns a salt to be used by theHashServiceduring hash computation, ornullif no salt is provided as part of the request. Note that anullvalue does not necessarily mean a salt won't be used at all - it just means that the request didn't include one. The servicingHashServiceis free to provide a salting strategy for a request, even if the request did not specify one.- Specified by:
getSaltin interfaceHashRequest- Returns:
- a salt to be used by the
HashServiceduring hash computation, ornullif no salt is provided as part of the request.
-
getIterations
public int getIterations()
Description copied from interface:HashRequestReturns the number of requested hash iterations to be performed when computing the finalHashresult. A non-positive (0 or less) indicates that theHashService's default iteration configuration should be used. A positive value overrides theHashService's configuration for a single request. Note that aHashServiceis free to ignore this number if it determines the number is not sufficient to meet a desired level of security.- Specified by:
getIterationsin interfaceHashRequest- Returns:
- the number of requested hash iterations to be performed when computing the final
Hashresult.
-
getAlgorithmName
public String getAlgorithmName()
Description copied from interface:HashRequestReturns the name of the hash algorithm theHashServiceshould use when computing theHash, ornullif the default algorithm configuration of theHashServiceshould be used. A non-null value overrides theHashService's configuration for a single request. Note that aHashServiceis free to ignore this value if it determines that the algorithm is not sufficient to meet a desired level of security.- Specified by:
getAlgorithmNamein interfaceHashRequest- Returns:
- the name of the hash algorithm the
HashServiceshould use when computing theHash, ornullif the default algorithm configuration of theHashServiceshould be used.
-
-