Class HOTPGenerator


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

    • HOTPGenerator

      public HOTPGenerator​(String secret)
      Constructs generator with default values
      Parameters:
      secret - used to generate hash
    • HOTPGenerator

      public HOTPGenerator​(int passwordLength, String secret)
      Constructs generator with custom password length
      Parameters:
      passwordLength - number of digits for generated code in range 6...8
      secret - used to generate hash
    • HOTPGenerator

      public HOTPGenerator​(URI uri) throws UnsupportedEncodingException
      Constructs generator from a OTPAuth URI
      Parameters:
      uri - OTPAuth URI
      Throws:
      UnsupportedEncodingException - when URI query can't be encodede
  • 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