Package org.keycloak.models.utils
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 Summary
Fields Modifier and Type Field Description protected String
algorithm
static String
DEFAULT_ALGORITHM
static int
DEFAULT_NUMBER_DIGITS
static String
HMAC_SHA1
static String
HMAC_SHA256
static String
HMAC_SHA512
protected int
lookAheadWindow
protected int
numberDigits
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
generateHOTP(String key, int counter)
String
generateOTP(String key, String counter, int returnDigits, String crypto)
This method generates an OTP value for the given set of parameters.static String
generateSecret(int length)
int
validateHOTP(String token, String key, int counter)
-
-
-
Field Detail
-
HMAC_SHA1
public static final String HMAC_SHA1
- See Also:
- Constant Field Values
-
HMAC_SHA256
public static final String HMAC_SHA256
- See Also:
- Constant Field Values
-
HMAC_SHA512
public static final String HMAC_SHA512
- See Also:
- Constant Field Values
-
DEFAULT_ALGORITHM
public static final String DEFAULT_ALGORITHM
- See Also:
- Constant Field Values
-
DEFAULT_NUMBER_DIGITS
public static final int DEFAULT_NUMBER_DIGITS
- See Also:
- Constant Field Values
-
algorithm
protected final String algorithm
-
numberDigits
protected final int numberDigits
-
lookAheadWindow
protected final int lookAheadWindow
-
-
Constructor Detail
-
HmacOTP
public HmacOTP(int numberDigits, String algorithm, int delayWindow)
-
-
Method Detail
-
generateSecret
public static String generateSecret(int length)
-
validateHOTP
public int validateHOTP(String token, String 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
-
generateOTP
public String generateOTP(String 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 encodedcounter
- a value that reflects a timereturnDigits
- number of digits to returncrypto
- the crypto function to use- Returns:
- A numeric String in base 10 that includes return digits
- Throws:
GeneralSecurityException
-
-