Kotlin Multiplatform library for OTP and TOTP password generation/validation
- MACs
- KotlinX-DateTime
- Okio (
Buffer
implementation) - Encoding (
Base32
implementation)
Add it in your root build.gradle
at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add dependency to module build.gradle
dependencies {
implementation("com.github.Luteoos:Simple-OTP:1.0.0")
}
HMacOTP(ByteArrayKey)
//or when using non-standard Algorithm
HMacOTP(codeLength = 6, algorithm = Algorithm.HmacSHA256(ByteArrayKey))
//or if you have key as String
HMacOTP(secretKey, encoding = KeyEncoding.BASE32)
//or
TimeOTP(key = byteArrayKey, timestep = 60.seconds)
HOTP
generator.generateOneTimePassword(counter)
TOTP
generator.generateTimedOneTimePassword(epochMillis)
//or
generator.generateTimedOneTimePassword(time = timeInstant)