Class HmacOTP

java.lang.Object
org.keycloak.models.utils.HmacOTP
Direct Known Subclasses:
TimeBasedOTP

public class HmacOTP extends Object
Version:
$Revision: 1 $
Author:
Bill Burke
  • Field Details

  • Constructor Details

    • HmacOTP

      public HmacOTP(int numberDigits, String algorithm, int delayWindow)
  • Method Details

    • generateSecret

      public static String generateSecret(int length)
    • generateHOTP

      public String generateHOTP(byte[] key, int counter)
    • generateHOTP

      public String generateHOTP(String key, int counter)
    • validateHOTP

      public int validateHOTP(String token, byte[] key, int counter)
      Parameters:
      token -
      key -
      counter -
      Returns:
      -1 if not a match. A positive number means successful validation. This positive number is also the new value of the counter
    • validateHOTP

      public int validateHOTP(String token, String key, int counter)
    • generateOTP

      public String generateOTP(byte[] key, String counter, int returnDigits, String crypto)
      This method generates an OTP value for the given set of parameters.
      Parameters:
      key - the shared secret, HEX encoded
      counter - a value that reflects a time
      returnDigits - number of digits to return
      crypto - the crypto function to use
      Returns:
      A numeric String in base 10 that includes return digits
      Throws:
      GeneralSecurityException