26 lines
510 B
Kotlin
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)
|
|
}
|
|
}
|
|
}
|