public final class TotpGeneratorContext extends OtpGeneratorContext
Constructor and Description |
---|
TotpGeneratorContext(java.lang.String secret,
int digits,
HmacAlgorithm algorithm)
Returns a new TotpGeneratorContext object with the values secret, digits
and algorithm.
|
TotpGeneratorContext(java.lang.String secret,
int digits,
HmacAlgorithm algorithm,
int period)
Returns a new TotpGeneratorContext object with the values secret, digits,
algorithm and period.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
create()
Returns a time-based one-time password for the current time of the system
|
java.lang.String |
create(int timeInterval)
Returns a time-based one-time password based on
T0 (GMT: Thu, 01 Jan 1970 00:00:00 GMT)
and the given period in seconds. |
java.lang.String |
create(long timeInMillis)
Returns a time-based one-time password based on
T0 (Thu, 01 Jan 1970 00:00:00 UTC),
the given UTC time in milliseconds and the period period set for this instance. |
static int |
remainingTime(int period)
Calculates the remaining time for a given period in seconds, based on
T0 (GMT: Thu, 01 Jan 1970 00:00:00 GMT) |
public TotpGeneratorContext(java.lang.String secret, int digits, HmacAlgorithm algorithm)
secret
- the secret key used to generate the password.digits
- a value of 6 or 8 representing the length of the password to be generated.
The default is 6.algorithm
- the HmacAlgorithm
used to generate the password.
The default is HmacAlgorithmSHA1.java.lang.IllegalArgumentException
- if any of the arguments is null or out of boundariespublic TotpGeneratorContext(java.lang.String secret, int digits, HmacAlgorithm algorithm, int period)
secret
- the secret key used to generate the password.digits
- a value of 6 or 8 representing the length of the password to be generated.
The default is 6.algorithm
- the HmacAlgorithm
used to generate the password.
The default is HmacAlgorithmSHA1.period
- a value between 10 and 300 representing the number of seconds the password
is valid. Default is 30.java.lang.IllegalArgumentException
- if any of the arguments is null or out of boundariespublic java.lang.String create(long timeInMillis) throws java.lang.IllegalArgumentException
T0
(Thu, 01 Jan 1970 00:00:00 UTC),
the given UTC time in milliseconds and the period
period set for this instance.
Ensure that the parameter has the correct type (long
). Otherwise
create(int)
will be called.timeInMillis
- the UTC time in millisecondsjava.lang.IllegalArgumentException
- if timeInMillis is < 0public java.lang.String create()
public java.lang.String create(int timeInterval)
T0
(GMT: Thu, 01 Jan 1970 00:00:00 GMT)
and the given period in seconds.timeInterval
- represents the time step in seconds, has to be > 0 and < 300java.lang.IllegalArgumentException
- if timeInterval is < 10 or > 300public static int remainingTime(int period)
T0
(GMT: Thu, 01 Jan 1970 00:00:00 GMT)period
- the period in seconds where the remaining time is needed,
has to be > 0java.lang.IllegalArgumentException
- if parameter is <= 0