Package dev.vink.jtotp
Class TOTPGenerator
java.lang.Object
dev.vink.jtotp.TOTPGenerator
Class for generating Time-based One-Time Passwords (TOTP) using HMAC values.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder class for constructing instances of TOTPGenerator. -
Method Summary
Modifier and TypeMethodDescriptiongenerateWithDrift
(int drift) Generates a TOTP with a custom drift in time steps.generateWithTime
(long time) Generates a TOTP for a specific time.next()
Generates the TOTP for the next time step.now()
Generates the current TOTP based on the current time.previous()
Generates the TOTP for the previous time step.
-
Method Details
-
now
Generates the current TOTP based on the current time.- Returns:
- The current TOTP as a string.
-
previous
Generates the TOTP for the previous time step.- Returns:
- The previous TOTP as a string.
-
next
Generates the TOTP for the next time step.- Returns:
- The next TOTP as a string.
-
generateWithDrift
Generates a TOTP with a custom drift in time steps.- Parameters:
drift
- The number of time steps to drift (positive or negative).- Returns:
- The TOTP with the specified drift as a string.
-
generateWithTime
Generates a TOTP for a specific time.- Parameters:
time
- The time in seconds since the Unix epoch.- Returns:
- The TOTP for the specified time as a string.
-