Package com.bastiaanjansen.otp
Class TOTPGenerator
- java.lang.Object
-
- com.bastiaanjansen.otp.TOTPGenerator
-
public final class TOTPGenerator extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTOTPGenerator.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringat(long secondsPast1970)Stringat(Instant instant)Stringat(LocalDate date)Stringat(Date date)DurationdurationUntilNextTimeWindow()Calculates time until next time window will be reached and a new totp should be generatedDurationdurationUntilNextTimeWindow(Clock clock)static TOTPGeneratorfromURI(URI uri)HMACAlgorithmgetAlgorithm()ClockgetClock()intgetPasswordLength()DurationgetPeriod()URIgetURI(String issuer)URIgetURI(String issuer, String account)Stringnow()Stringnow(Clock clock)booleanverify(String code)booleanverify(String code, int delayWindow)Checks whether a code is valid for a specific counter taking a delay window into accountstatic TOTPGeneratorwithDefaultValues(byte[] secret)
-
-
-
Method Detail
-
fromURI
public static TOTPGenerator fromURI(URI uri) throws URISyntaxException
- Throws:
URISyntaxException
-
withDefaultValues
public static TOTPGenerator withDefaultValues(byte[] secret)
-
now
public String now() throws IllegalStateException
- Throws:
IllegalStateException
-
now
public String now(Clock clock) throws IllegalStateException
- Throws:
IllegalStateException
-
at
public String at(Instant instant) throws IllegalStateException
- Throws:
IllegalStateException
-
at
public String at(Date date) throws IllegalStateException
- Throws:
IllegalStateException
-
at
public String at(LocalDate date) throws IllegalStateException
- Throws:
IllegalStateException
-
at
public String at(long secondsPast1970) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
verify
public boolean verify(String code)
-
verify
public boolean verify(String code, int delayWindow)
Checks whether a code is valid for a specific counter taking a delay window into account- Parameters:
code- an OTP codedelayWindow- window in which a code can still be deemed valid- Returns:
- a boolean, true if code is valid, otherwise false
-
getURI
public URI getURI(String issuer) throws URISyntaxException
- Throws:
URISyntaxException
-
getURI
public URI getURI(String issuer, String account) throws URISyntaxException
- Throws:
URISyntaxException
-
durationUntilNextTimeWindow
public Duration durationUntilNextTimeWindow()
Calculates time until next time window will be reached and a new totp should be generated- Returns:
- a duration object with duration until next time window
-
getPeriod
public Duration getPeriod()
-
getClock
public Clock getClock()
-
getAlgorithm
public HMACAlgorithm getAlgorithm()
-
getPasswordLength
public int getPasswordLength()
-
-