TimeBasedOneTimePasswordGenerator

open class TimeBasedOneTimePasswordGenerator(secret: ByteArray, config: TimeBasedOneTimePasswordConfig)

Generator for the RFC 6238 "TOTP: Time-Based One-Time Password Algorithm" (https://tools.ietf.org/html/rfc6238)

Constructors

Link copied to clipboard
fun TimeBasedOneTimePasswordGenerator(secret: ByteArray, config: TimeBasedOneTimePasswordConfig)

Functions

Link copied to clipboard
fun counter(instant: Instant): Long
fun counter(date: Date): Long

Convenience method for counter.

fun counter(timestamp: Long = System.currentTimeMillis()): Long

Calculate the current time slot.

Link copied to clipboard
fun generate(instant: Instant): String
fun generate(date: Date): String

Convenience method for generate.

fun generate(timestamp: Long = System.currentTimeMillis()): String

Generates a code representing the time-based one-time password.

Link copied to clipboard
fun isValid(code: String, instant: Instant): Boolean
fun isValid(code: String, date: Date): Boolean

Convenience method for isValid.

fun isValid(code: String, timestamp: Long = System.currentTimeMillis()): Boolean

Validates the given code.

Link copied to clipboard
fun otpAuthUriBuilder(): OtpAuthUriBuilder.Totp

Creates an OtpAuthUriBuilder, which pre-configured with the secret, as well as the algorithm, code digits and time step from the config.

Link copied to clipboard
fun timeslotStart(counter: Long): Long

Calculates the start of the given time slot.