Class OTPGenerator.Builder<B,G>

java.lang.Object
com.bastiaanjansen.otp.OTPGenerator.Builder<B,G>
Type Parameters:
B - concrete builder class
Direct Known Subclasses:
HOTPGenerator.Builder, TOTPGenerator.Builder
Enclosing class:
OTPGenerator

protected abstract static class OTPGenerator.Builder<B,G> extends Object
Abstract OTP builder
Author:
Bastiaan Jansen
  • Field Details

    • passwordLength

      protected int passwordLength
      Number of digits for generated code in range 6...8, defaults to 6
    • algorithm

      protected HMACAlgorithm algorithm
      Hashing algorithm used to generate code, defaults to SHA1
    • secret

      protected byte[] secret
      Secret key used to generate the code, this should be a base32 string
    • DEFAULT_PASSWORD_LENGTH

      public static final int DEFAULT_PASSWORD_LENGTH
      Default value for password length
      See Also:
    • DEFAULT_HMAC_ALGORITHM

      public static final HMACAlgorithm DEFAULT_HMAC_ALGORITHM
      Default value for HMAC Algorithm
  • Constructor Details

    • Builder

      public Builder(byte[] secret)
  • Method Details

    • withPasswordLength

      public B withPasswordLength(int passwordLength)
      Change password length of code
      Parameters:
      passwordLength - number of digits for generated code in range 6...8
      Returns:
      concrete builder
    • withAlgorithm

      public B withAlgorithm(HMACAlgorithm algorithm)
      Change hashing algorithm
      Parameters:
      algorithm - HMAC hashing algorithm
      Returns:
      concrete builder
    • getSecret

      public byte[] getSecret()
    • getPasswordLength

      public int getPasswordLength()
    • getAlgorithm

      public HMACAlgorithm getAlgorithm()
    • getBuilder

      public abstract B getBuilder()
    • build

      public abstract G build()