Class Sha256OneTimeCodeHasher
java.lang.Object
com.irurueta.authserver.authorization.application.ott.Sha256OneTimeCodeHasher
- All Implemented Interfaces:
OneTimeCodeHasher
Hashes one-time codes with SHA-256 (lower-case hex) and compares them in constant time.
A plain hash of a six-digit code can be brute-forced in an instant if the table leaks. That is acceptable here only because a code is single use, lives for minutes and is burnt after a few wrong attempts, so a leaked row is useless by the time anyone could read it. Never use this hasher for a long-lived secret.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
ALGORITHM
Name of the digest algorithm.- See Also:
-
-
Constructor Details
-
Sha256OneTimeCodeHasher
public Sha256OneTimeCodeHasher()
-
-
Method Details
-
hash
Hashes a code.- Specified by:
hashin interfaceOneTimeCodeHasher- Parameters:
code- the clear-text code.- Returns:
- the hash as lower-case hex.
-
matches
Tells whether a code produces a hash, in constant time.- Specified by:
matchesin interfaceOneTimeCodeHasher- Parameters:
code- the clear-text code, possiblynull.hash- the stored hash, possiblynull.- Returns:
truewhen they correspond.
-
digest
Computes the SHA-256 digest of a text.- Parameters:
text- the text.- Returns:
- the digest bytes.
-