secure-random
Kotlin Multiplatform library for obtaining cryptographically
secure random data from the system. Modeled after Java's SecureRandom
class, it provides a simple API surface area. Under the hood it
utilizes system functions so that SecureRandom
is accessible from
common code.
Heavily inspired by the rust-random/getrandom crate for the native Linux/Android implementation.
A full list of kotlin-components
projects can be found HERE
Example Usages
fun main() {
val sRandom = SecureRandom()
val bytes: ByteArray = try {
sRandom.nextBytesOf(count = 20)
} catch (e: SecRandomCopyException) {
e.printStackTrace()
return
}
println(bytes.toList())
}
fun main() {
val sRandom = SecureRandom()
val bytes = ByteArray(20)
try {
sRandom.nextBytesCopyTo(bytes)
} catch (e: SecRandomCopyException) {
e.printStackTrace()
return
}
println(bytes.toList())
}
Samples
See the native sample
Get Started
// build.gradle.kts
dependencies {
implementation("io.matthewnelson.kotlin-components:secure-random:0.1.2")
}
// build.gradle
dependencies {
implementation "io.matthewnelson.kotlin-components:secure-random:0.1.2"
}
Kotlin Version Compatibility
secure-random | kotlin |
---|---|
0.1.2 | 1.8.0 |
0.1.1 | 1.8.0 |
0.1.0 | 1.8.0 |
Git
This project utilizes git submodules. You will need to initialize them when cloning the repository via:
$ git clone --recursive https://github.com/05nelsonm/secure-random.git
If you've already cloned the repository, run:
$ git checkout master
$ git pull
$ git submodule update --init
In order to keep submodules updated when pulling the latest code, run:
$ git pull --recurse-submodules