Class SecureTokenGenerator
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.keys.SecureTokenGenerator
- All Implemented Interfaces:
TokenGenerator
TokenGenerator that creates tokens from a SecureRandom and hashes them with SHA-256. The tokens
are random with 256 bits of entropy, so a fast deterministic hash is enough to store them.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringName of the hash algorithm.private final SecureRandomSource of randomness.(package private) static final intNumber of random bytes of a token. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
TOKEN_BYTES
static final int TOKEN_BYTESNumber of random bytes of a token.- See Also:
-
ALGORITHM
Name of the hash algorithm.- See Also:
-
random
Source of randomness.
-
-
Constructor Details
-
SecureTokenGenerator
public SecureTokenGenerator()
-
-
Method Details
-
generate
Description copied from interface:TokenGeneratorCreates an unguessable URL-safe token.- Specified by:
generatein interfaceTokenGenerator- Returns:
- the token.
-
hash
Description copied from interface:TokenGeneratorHashes a token with a deterministic, one-way function, so a stored hash can be looked up by the presented token.- Specified by:
hashin interfaceTokenGenerator- Parameters:
token- the token value.- Returns:
- the hash.
-
digest
Hashes a token with a message digest algorithm.- Parameters:
algorithm- name of the algorithm.token- the token value.- Returns:
- the URL-safe, unpadded Base64 digest.
- Throws:
IllegalStateException- if the algorithm is not available.
-