upgrade
Some checks failed
/ test (push) Has been cancelled
/ publish (push) Has been cancelled

too tired to write a detailed commit message or split into self-explanatory commits
This commit is contained in:
2026-01-29 18:11:17 +01:00
parent f85e22311d
commit d2b901a6ff
7 changed files with 50 additions and 108 deletions

View File

@@ -6,15 +6,6 @@ Supported algorithms:
- 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`.
@@ -25,36 +16,24 @@ repositories {
}
dependencies {
implementation("com.infendro:otp:1.2.2")
implementation("com.infendro:otp:1.3.0")
}
```
## Usage
```kotlin
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))
// create TOTP instance
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)
// generate and verify OTP
val now = System.now()
val otp = totp.generate(<secret>, now)
totp.verify(<secret>, now, otp)
}
```