Package org.keycloak.models.utils
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 Summary
Fields Modifier and Type Field Description static int
DEFAULT_DELAY_WINDOW
static int
DEFAULT_INTERVAL_SECONDS
-
Fields inherited from class org.keycloak.models.utils.HmacOTP
algorithm, DEFAULT_ALGORITHM, DEFAULT_NUMBER_DIGITS, HMAC_SHA1, HMAC_SHA256, HMAC_SHA512, lookAheadWindow, numberDigits
-
-
Constructor Summary
Constructors Constructor Description TimeBasedOTP()
TimeBasedOTP(String algorithm, int numberDigits, int timeIntervalInSeconds, int lookAroundWindow)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
generateTOTP(String secretKey)
Generates a token.void
setCalendar(Calendar calendar)
boolean
validateTOTP(String token, byte[] secret)
Validates a token using a secret key.-
Methods inherited from class org.keycloak.models.utils.HmacOTP
generateHOTP, generateOTP, generateSecret, validateHOTP
-
-
-
-
Field Detail
-
DEFAULT_INTERVAL_SECONDS
public static final int DEFAULT_INTERVAL_SECONDS
- See Also:
- Constant Field Values
-
DEFAULT_DELAY_WINDOW
public static final int DEFAULT_DELAY_WINDOW
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TimeBasedOTP
public TimeBasedOTP()
-
TimeBasedOTP
public TimeBasedOTP(String algorithm, int numberDigits, int timeIntervalInSeconds, int lookAroundWindow)
- Parameters:
algorithm
- the encryption algorithmnumberDigits
- the number of digits for tokenstimeIntervalInSeconds
- the number of seconds a token is validlookAroundWindow
- the number of previous and following intervals that should be used to validate tokens.
-
-
Method Detail
-
generateTOTP
public String generateTOTP(String secretKey)
Generates a token.
- Parameters:
secretKey
- the secret key to derive the token from.
-
validateTOTP
public boolean validateTOTP(String token, byte[] secret)
Validates a token using a secret key.
- Parameters:
token
- OTP string to validatesecret
- Shared secret- Returns:
- true of the token is valid
-
setCalendar
public void setCalendar(Calendar calendar)
-
-