This commit is contained in:
25
src/commonMain/kotlin/com/infendro/otp/SecretGenerator.kt
Normal file
25
src/commonMain/kotlin/com/infendro/otp/SecretGenerator.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user