2025-12-13 01:53:20 +01:00
2025-07-12 20:04:39 +02:00
2025-12-13 23:28:41 +01:00
2025-08-17 14:52:48 +02:00
2025-08-17 14:52:48 +02:00
2025-07-12 20:04:39 +02:00
2025-12-13 23:29:47 +01:00

otp-kt

otp-kt is a Kotlin Multiplatform library that provides common one-time password implementations.

Supported implementations:

  • HOTP
  • TOTP

Targets

Target Status
JVM Supported
JavaScript Supported
Native (Linux) Supported
Native (Windows) Not Supported

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.2.2")
}

Usage

import com.infendro.hash.sha1.SHA1
import com.infendro.otp.SecretGenerator
import com.infendro.otp.TOTP
import com.infendro.random.csprng.CSPRNG
import kotlin.time.Clock.System.now
import kotlin.time.Duration.Companion.seconds

fun main() {
    // create a SecretGenerator and TOTP instance
    val generator = SecretGenerator(CSPRNG.HMAC(SHA1))
    val totp = TOTP(
        function = SHA1,
        length = 6,
        period = 30.seconds,
    )

    // generate a secret using SHA1
    val secret = generator.generate()

    // generate an OTP
    val otp = totp.generate(secret, now())

    // verify an OTP
    totp.verify(secret, now(), otp)
}
Description
No description provided
Readme 168 KiB
Languages
Kotlin 100%