Package org.cryptacular.generator
Class TOTPGenerator
java.lang.Object
org.cryptacular.generator.AbstractOTPGenerator
org.cryptacular.generator.TOTPGenerator
OTP generator component that implements the TOTP scheme described in
RFC 6238.
- Author:
- Middleware Services
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected longintgenerate(byte[] key) Generates the OTP given a per-user key.protected org.bouncycastle.crypto.DigestSpec<org.bouncycastle.crypto.Digest> intintprotected voidsetCurrentTime(long epochSeconds) Sets the current time (supports testing).voidsetDigestSpecification(Spec<org.bouncycastle.crypto.Digest> specification) Sets the digest algorithm used with the HMAC function.voidsetStartTime(int seconds) Sets the reference start time, T0.voidsetTimeStep(int seconds) Sets the time step, X.Methods inherited from class org.cryptacular.generator.AbstractOTPGenerator
generateInternal, getNumberOfDigits, setNumberOfDigits
-
Constructor Details
-
TOTPGenerator
public TOTPGenerator()
-
-
Method Details
-
getDigestSpecification
- Returns:
- Digest algorithm used with the HMAC function.
-
setDigestSpecification
Sets the digest algorithm used with the HMAC function.- Parameters:
specification- SHA-1, SHA-256, or SHA-512 digest specification.
-
getStartTime
public int getStartTime()- Returns:
- Reference start time.
-
setStartTime
public void setStartTime(int seconds) Sets the reference start time, T0. Default 0, i.e. 1970-01-01T00:00:00.- Parameters:
seconds- Start time in seconds.
-
getTimeStep
public int getTimeStep()- Returns:
- Time step in seconds.
-
setTimeStep
public void setTimeStep(int seconds) Sets the time step, X.- Parameters:
seconds- Time step in seconds. Default is 30. This value determines the validity window of generated OTP values.
-
generate
public int generate(byte[] key) Generates the OTP given a per-user key.- Parameters:
key- Per-user key.- Returns:
- Integer OTP.
-
getDigest
protected org.bouncycastle.crypto.Digest getDigest()- Specified by:
getDigestin classAbstractOTPGenerator- Returns:
- Digest algorithm used for HMAC operation.
-
setCurrentTime
protected void setCurrentTime(long epochSeconds) Sets the current time (supports testing). This value is used if and only if it is a non-negative value; otherwise the current system time is used.- Parameters:
epochSeconds- Seconds since the start of the epoch, 1970-01-01T00:00:00.
-
currentTime
protected long currentTime()- Returns:
- Current system time in seconds since the start of epoch, 1970-01-01T00:00:00.
-