Files
otp.kt/src/commonMain/kotlin/com/infendro/otp/SecretGenerator.kt
Infendro 1300e1d728
All checks were successful
/ publish (push) Successful in 3m9s
initial commit
2025-07-12 20:04:39 +02:00

26 lines
510 B
Kotlin

package com.infendro.otp
import com.infendro.hash.*
import kotlin.random.Random
object SecretGenerator {
private val random = Random.Default
fun generate(
algorithm: HashFunction = SHA1,
): ByteArray {
val bytes = when (algorithm) {
MD5 -> 16
SHA1 -> 20
SHA224 -> 28
SHA256 -> 32
SHA384 -> 48
SHA512 -> 64
}
return ByteArray(bytes).also {
random.nextBytes(it)
}
}
}