2025-10-04 12:22:45 +02:00
2025-07-12 20:04:39 +02:00
2025-08-17 14:52:48 +02:00
2025-07-12 20:04:39 +02:00
2025-07-24 21:07:58 +02: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-10-04 12:22:45 +02:00
2025-07-12 20:04:39 +02:00

Kotlin OTP

This library provides various One-Time Password implementations in Kotlin Multiplatform.

Features

  • HTOP
  • TOTP
  • Multiplatform support
    • JVM
    • JavaScript
    • Native (Linux)

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
No description provided
Readme 168 KiB
Languages
Kotlin 100%