Class TimeBasedOTP

java.lang.Object
org.keycloak.models.utils.HmacOTP
org.keycloak.models.utils.TimeBasedOTP

public class TimeBasedOTP extends HmacOTP
TOTP: Time-based One-time Password Algorithm Based on http://tools.ietf.org/html/draft-mraihi-totp-timebased-06
Since:
Sep 20, 2010
Author:
anil saldhana
  • Field Details

  • Constructor Details

    • TimeBasedOTP

      public TimeBasedOTP()
    • TimeBasedOTP

      public TimeBasedOTP(String algorithm, int numberDigits, int timeIntervalInSeconds, int lookAroundWindow)
      Parameters:
      algorithm - the encryption algorithm
      numberDigits - the number of digits for tokens
      timeIntervalInSeconds - the number of seconds a token is valid
      lookAroundWindow - the number of previous and following intervals that should be used to validate tokens.
  • Method Details

    • generateTOTP

      public String generateTOTP(byte[] secretKey)

      Generates a token.

      Parameters:
      secretKey - the secret key to derive the token from.
    • generateTOTP

      public String generateTOTP(String secretKey)
    • validateTOTP

      public boolean validateTOTP(String token, byte[] secret)

      Validates a token using a secret key.

      Parameters:
      token - OTP string to validate
      secret - Shared secret
      Returns:
      true of the token is valid
    • setCalendar

      public void setCalendar(Calendar calendar)