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