
OTP generator implementing RFC 4226/6238 for HOTP and TOTP, with configurable HMAC algorithm, digit length, secret handling and adjustable time-step for time-based codes.
This project provides a Kotlin Multiplatform library for generating OTP codes.
It is an implementation of the RFC 4226 and the RFC 6238 and provides:
The multiplatform library currently supports:
Planned support:
This library is available on Maven Central:
For multiplatform project:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.vicart.kotp:kotp:0.0.2")
}
}
}For other platforms:
dependencies {
implementation("dev.vicart.kotp:kotp:0.0.2")
}pom.xml
<dependency>
<groupId>dev.vicart.kotp</groupId>
<artifactId>kotp</artifactId>
<version>0.0.2</version>
</dependency>HMAC-based One-Time Password (HOTP) and Time-based One-Time Password (TOTP) are two methods of generating one-time passwords. Their goal is to provide a 2FA solution for securing access to sensitive data. Both of them are based on a secret key and a counter and use a HMAC function to generate a unique password. The secret key is usually a Base32-encoded string provided by the server.
HOTP uses a 64-bit number as a value for the counter. This counter is aimed to be incremented after each use and must be synchronized between the client and the server.
TOTP extends HOTP by using the time as a shared counter between the client and the server.
It can be configured for a code to be valid for a specific time interval (usually 30 seconds). However, a server may check the provided code against the previous and the next time interval for error correction.
val configuration = HmacOneTimePasswordConfiguration(
secret = <encoded secret>,
digits = 6, //The number of digits in the code
hmacAlgorithm = HmacAlgorithm.SHA1 //The HMAC algorithm to use
)
val generator = HmacOneTimePasswordGenerator(configuration)
val counter = 0
val code = generator.generateCode(counter) //Returns "123456" for exampleval configuration = TimeOneTimePasswordConfiguration(
secret = <encoded secret>,
digits = 6,
hmacAlgorithm = HmacAlgorithm.SHA1,
timeStep = 30.seconds
)
val generator = TimeOneTimePasswordGenerator(configuration)
val code = generator.generateCode() //Returns "123456" for exampleYou can find the documentation here
This project provides a Kotlin Multiplatform library for generating OTP codes.
It is an implementation of the RFC 4226 and the RFC 6238 and provides:
The multiplatform library currently supports:
Planned support:
This library is available on Maven Central:
For multiplatform project:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.vicart.kotp:kotp:0.0.2")
}
}
}For other platforms:
dependencies {
implementation("dev.vicart.kotp:kotp:0.0.2")
}pom.xml
<dependency>
<groupId>dev.vicart.kotp</groupId>
<artifactId>kotp</artifactId>
<version>0.0.2</version>
</dependency>HMAC-based One-Time Password (HOTP) and Time-based One-Time Password (TOTP) are two methods of generating one-time passwords. Their goal is to provide a 2FA solution for securing access to sensitive data. Both of them are based on a secret key and a counter and use a HMAC function to generate a unique password. The secret key is usually a Base32-encoded string provided by the server.
HOTP uses a 64-bit number as a value for the counter. This counter is aimed to be incremented after each use and must be synchronized between the client and the server.
TOTP extends HOTP by using the time as a shared counter between the client and the server.
It can be configured for a code to be valid for a specific time interval (usually 30 seconds). However, a server may check the provided code against the previous and the next time interval for error correction.
val configuration = HmacOneTimePasswordConfiguration(
secret = <encoded secret>,
digits = 6, //The number of digits in the code
hmacAlgorithm = HmacAlgorithm.SHA1 //The HMAC algorithm to use
)
val generator = HmacOneTimePasswordGenerator(configuration)
val counter = 0
val code = generator.generateCode(counter) //Returns "123456" for exampleval configuration = TimeOneTimePasswordConfiguration(
secret = <encoded secret>,
digits = 6,
hmacAlgorithm = HmacAlgorithm.SHA1,
timeStep = 30.seconds
)
val generator = TimeOneTimePasswordGenerator(configuration)
val code = generator.generateCode() //Returns "123456" for exampleYou can find the documentation here