add secure methods (#44)

This commit is contained in:
Alexander Buntakov 2021-08-11 20:12:37 +03:00 committed by GitHub
parent 195d2f16c9
commit 7c73d2418c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -8,4 +8,12 @@ object ByteUtils {
}
}
fun decodeHex(hex: String): ByteArray {
check(hex.length % 2 == 0) { "Must have an even length" }
return hex.chunked(2)
.map { it.toInt(16).toByte() }
.toByteArray()
}
}

View File

@ -24,4 +24,6 @@ object SecureRandomStringGenerator {
}
}
fun generateRandomBytes(size: Int) = ByteArray(size).also(SecureRandom()::nextBytes)
}