Class SecureTokenGenerator

java.lang.Object
com.irurueta.authserver.authorization.infrastructure.keys.SecureTokenGenerator
All Implemented Interfaces:
TokenGenerator

@Component public class SecureTokenGenerator extends Object implements 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 Details

  • Constructor Details

    • SecureTokenGenerator

      public SecureTokenGenerator()
  • Method Details

    • generate

      public String generate()
      Description copied from interface: TokenGenerator
      Creates an unguessable URL-safe token.
      Specified by:
      generate in interface TokenGenerator
      Returns:
      the token.
    • hash

      public String hash(String token)
      Description copied from interface: TokenGenerator
      Hashes a token with a deterministic, one-way function, so a stored hash can be looked up by the presented token.
      Specified by:
      hash in interface TokenGenerator
      Parameters:
      token - the token value.
      Returns:
      the hash.
    • digest

      static String digest(String algorithm, String token)
      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.