public class TimeBasedOTP extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_ALGORITHM |
static int |
DEFAULT_DELAY_WINDOW |
static int |
DEFAULT_INTERVAL_SECONDS |
static int |
DEFAULT_NUMBER_DIGITS |
static String |
HMAC_SHA1 |
static String |
HMAC_SHA256 |
static String |
HMAC_SHA512 |
| Constructor and Description |
|---|
TimeBasedOTP() |
TimeBasedOTP(String algorithm,
int numberDigits,
int timeIntervalInSeconds,
int delayWindow) |
| Modifier and Type | Method and Description |
|---|---|
String |
generate(String secretKey)
Generates a token.
|
String |
generateTOTP(String key,
String time,
int returnDigits,
String crypto)
This method generates an TOTP value for the given set of parameters.
|
void |
setCalendar(Calendar calendar) |
boolean |
validate(String token,
byte[] secret)
Validates a token using a secret key.
|
public static final String HMAC_SHA1
public static final String HMAC_SHA256
public static final String HMAC_SHA512
public static final String DEFAULT_ALGORITHM
public static final int DEFAULT_NUMBER_DIGITS
public static final int DEFAULT_INTERVAL_SECONDS
public static final int DEFAULT_DELAY_WINDOW
public TimeBasedOTP()
public TimeBasedOTP(String algorithm, int numberDigits, int timeIntervalInSeconds, int delayWindow)
algorithm - the encryption algorithmnumberDigits - the number of digits for tokenstimeIntervalInSeconds - the number of seconds a token is validdelayWindow - the number of previous intervals that should be used to validate tokens.public String generate(String secretKey)
Generates a token.
secretKey - the secret key to derive the token from.public String generateTOTP(String key, String time, int returnDigits, String crypto)
key - the shared secret, HEX encodedtime - a value that reflects a timereturnDigits - number of digits to returncrypto - the crypto function to usetruncationDigits digitsGeneralSecurityExceptionpublic boolean validate(String token, byte[] secret)
Validates a token using a secret key.
token - OTP string to validatesecret - Shared secretpublic void setCalendar(Calendar calendar)
Copyright © 2018 JBoss by Red Hat. All rights reserved.