Class TOTPGenerator

java.lang.Object
dev.vink.jtotp.TOTPGenerator

public class TOTPGenerator extends Object
Class for generating Time-based One-Time Passwords (TOTP) using HMAC values.
  • Method Details

    • now

      public String now()
      Generates the current TOTP based on the current time.
      Returns:
      The current TOTP as a string.
    • previous

      public String previous()
      Generates the TOTP for the previous time step.
      Returns:
      The previous TOTP as a string.
    • next

      public String next()
      Generates the TOTP for the next time step.
      Returns:
      The next TOTP as a string.
    • generateWithDrift

      public String generateWithDrift(int drift)
      Generates a TOTP with a custom drift in time steps.
      Parameters:
      drift - The number of time steps to drift (positive or negative).
      Returns:
      The TOTP with the specified drift as a string.
    • generateWithTime

      public String generateWithTime(long time)
      Generates a TOTP for a specific time.
      Parameters:
      time - The time in seconds since the Unix epoch.
      Returns:
      The TOTP for the specified time as a string.