Yet Another OTP generator
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Totp.kt 840B

123456789101112131415161718
  1. package com.chameth.yaotp.algos
  2. import java.nio.ByteBuffer
  3. data class TotpParams(val hotpParams: HotpParams, val startTime: Long = 0, val step: Int = 30)
  4. fun totp(totpParams: TotpParams, currentTime: Long = currentTime()): Otp {
  5. val hotp = hotp(totpParams.hotpParams, count(totpParams.startTime, totpParams.step, currentTime).toByteArray())
  6. return Otp(hotp.otp, expiry(totpParams.startTime, totpParams.step, currentTime))
  7. }
  8. internal fun count(startTime: Long, step: Int, currentTime: Long) = (currentTime - startTime) / step
  9. internal fun currentTime() = System.currentTimeMillis() / 1000
  10. internal fun Long.toByteArray() = ByteBuffer.allocate(java.lang.Long.BYTES).putLong(this).array()
  11. internal fun expiry(startTime: Long, step: Int, currentTime: Long) = currentTime + step - (currentTime - startTime) % step