Skip to content

Kotlin Multiplatform library for OTP and TOTP password generation/validation

License

Notifications You must be signed in to change notification settings

Luteoos/Simple-OTP

Repository files navigation

Simple-OTP

Kotlin Multiplatform library for OTP and TOTP password generation/validation

GitHub tag License Status - Experimental

Dependencies

Installation

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

Usage

Initialize TimeOTP or HMacOTP

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)

Generate OTP

HOTP

generator.generateOneTimePassword(counter)

TOTP

generator.generateTimedOneTimePassword(epochMillis)

//or

generator.generateTimedOneTimePassword(time = timeInstant)

Validate existing OTP using isValid(StringOTP, counter)

License

MIT