Yet Another OTP generator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Totp.kt 572B

123456789101112
  1. package com.chameth.yaotp.algos
  2. import java.nio.ByteBuffer
  3. fun totp(key: ByteArray, startTime: Long = 0, step: Int = 30, currentTime: Long = currentTime(), length: Int = 6, hmacFunc: HmacFunc = ::hmacSha1)
  4. = hotp(key, count(startTime, step, currentTime).toByteArray(), length, hmacFunc)
  5. internal fun count(startTime: Long, step: Int, currentTime: Long) = (currentTime - startTime) / step
  6. internal fun currentTime() = System.currentTimeMillis() / 1000
  7. internal fun Long.toByteArray() = ByteBuffer.allocate(java.lang.Long.BYTES).putLong(this).array()