Class TOTPGenerator

java.lang.Object
org.cryptacular.generator.AbstractOTPGenerator
org.cryptacular.generator.TOTPGenerator

public class TOTPGenerator extends AbstractOTPGenerator
OTP generator component that implements the TOTP scheme described in RFC 6238.
Author:
Middleware Services
  • Constructor Details

    • TOTPGenerator

      public TOTPGenerator()
  • Method Details

    • getDigestSpecification

      public Spec<org.bouncycastle.crypto.Digest> getDigestSpecification()
      Returns:
      Digest algorithm used with the HMAC function.
    • setDigestSpecification

      public void setDigestSpecification(Spec<org.bouncycastle.crypto.Digest> specification)
      Sets the digest algorithm used with the HMAC function.
      Parameters:
      specification - SHA-1, SHA-256, or SHA-512 digest specification.
    • getStartTime

      public int getStartTime()
      Returns:
      Reference start time.
    • setStartTime

      public void setStartTime(int seconds)
      Sets the reference start time, T0. Default 0, i.e. 1970-01-01T00:00:00.
      Parameters:
      seconds - Start time in seconds.
    • getTimeStep

      public int getTimeStep()
      Returns:
      Time step in seconds.
    • setTimeStep

      public void setTimeStep(int seconds)
      Sets the time step, X.
      Parameters:
      seconds - Time step in seconds. Default is 30. This value determines the validity window of generated OTP values.
    • generate

      public int generate(byte[] key)
      Generates the OTP given a per-user key.
      Parameters:
      key - Per-user key.
      Returns:
      Integer OTP.
    • getDigest

      protected org.bouncycastle.crypto.Digest getDigest()
      Specified by:
      getDigest in class AbstractOTPGenerator
      Returns:
      Digest algorithm used for HMAC operation.
    • setCurrentTime

      protected void setCurrentTime(long epochSeconds)
      Sets the current time (supports testing). This value is used if and only if it is a non-negative value; otherwise the current system time is used.
      Parameters:
      epochSeconds - Seconds since the start of the epoch, 1970-01-01T00:00:00.
    • currentTime

      protected long currentTime()
      Returns:
      Current system time in seconds since the start of epoch, 1970-01-01T00:00:00.