-
Notifications
You must be signed in to change notification settings - Fork 0
4. TOTP
indrajit edited this page Jul 21, 2020
·
1 revision
Config
val config = TOTPConfig("secret", "KOTP-LIB", digits = 6, interval = 30, digest = Digest.SHA1)
// or
val config = TOTPConfig(Base32.encode("secret"), "KOTP-LIB", digits = 6, interval = 30, digest = Digest.SHA1)
// or
val config = TOTPConfig("secret", "KOTP-LIB")
// or
val config = TOTPConfig(Base32.encode("secret"), "KOTP-LIB")
TOTP
val totp = TOTP(config)
Otp generation
val time = Calendar.getInstance().apply { timeInMillis = 1_234_567_890 }.time
totp.at(time) // 515493
totp.now() // 351991
Verification
totp.verify("515493", at = time) // 1234560 => verified
totp.verify("000000", at = time) // null => not verified
Provisioning Uri
totp.provisioningUri("KOTP") // otpauth://totp/KOTP-LIB:KOTP?secret=ONSWG4TFOQ&period=30&issuer=KOTP-LIB&digits=6&algorithm=SHA1
Copyright (c) 2020 indrajit