Class 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
    • Constructor Detail

      • 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 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:
        true of the token is valid
      • setCalendar

        public void setCalendar​(Calendar calendar)