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 and 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 and Description
    `TimeBasedOTP()`
    `TimeBasedOTP(String algorithm, int numberDigits, int timeIntervalInSeconds, int lookAheadWindow)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and 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`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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 lookAheadWindow)

      Parameters:
        `algorithm` - the encryption algorithm
        `numberDigits` - the number of digits for tokens
        `timeIntervalInSeconds` - the number of seconds a token is valid
        `lookAheadWindow` - the number of previous 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 validate
        `secret` - Shared secret
      Returns:

    - #### setCalendar

          public void setCalendar(Calendar calendar)

Copyright © 2016 JBoss by Red Hat. All rights reserved.