e8999ae4e4715a75f82b4b633e6652be526f5259
Kotlin OTP
This library provides various One-Time Password implementations in Kotlin Multiplatform.
Features
Installation
Add the following to your build.gradle.kts.
repositories {
maven("https://git.infendro.com/api/packages/Infendro/maven")
}
dependencies {
implementation("com.infendro:otp:1.1.1")
}
Usage
import com.infendro.hash.SHA1
import com.infendro.otp.SecretGenerator
import com.infendro.otp.TOTP
import kotlin.time.Clock.System.now
import kotlin.time.Duration.Companion.seconds
fun main() {
// create a TOTP instance using SHA1, a length of 6, and a period of 30 seconds
val totp = TOTP(
function = SHA1,
length = 6,
period = 30.seconds,
)
// generate a secret using SHA1
val secret = SecretGenerator.generate(SHA1)
// generate an OTP
val otp = totp.generate(secret, now())
// verify an OTP
totp.verify(secret, now(), otp)
}
Description
Languages
Kotlin
100%