Class HOTPGenerator

java.lang.Object
com.bastiaanjansen.otp.OTPGenerator
com.bastiaanjansen.otp.HOTPGenerator

public class HOTPGenerator
extends OTPGenerator
Generates counter-based one-time passwords
Author:
Bastiaan Jansen
See Also:
OTPGenerator
  • Constructor Details

    • HOTPGenerator

      public HOTPGenerator​(int passwordLength, HMACAlgorithm algorithm, byte[] secret)
      Constructs generator with custom password length
      Parameters:
      passwordLength - number of digits for generated code in range 6...8
      algorithm - HMAC hash algorithm used to hash data
      secret - used to generate hash
  • Method Details

    • generate

      public String generate​(long counter) throws IllegalArgumentException
      Generate a counter-based one-time password
      Parameters:
      counter - how many times time interval has passed since 1970
      Returns:
      generated HOTP code
      Throws:
      IllegalArgumentException - when code could not be generated
    • getURI

      public URI getURI​(int counter, String issuer) throws URISyntaxException
      Create an OTPAuth URI for easy user on-boarding with only an issuer
      Parameters:
      counter - of URI
      issuer - name for URI
      Returns:
      OTPAuth URI
      Throws:
      URISyntaxException - when URI cannot be created
    • getURI

      public URI getURI​(int counter, String issuer, String account) throws URISyntaxException
      Create an OTPAuth URI for easy user on-boarding with an issuer and account name
      Parameters:
      counter - of URI
      issuer - name for URI
      account - name for URI
      Returns:
      OTPAuth URI
      Throws:
      URISyntaxException - when URI cannot be created