io.matthewnelson.kotlin-components:secure-random-androidnativearm64

Kotlin Components' SecureRandom Component


Keywords
android, android-lib, android-library, android-libs, kotlin, kotlin-android, kotlin-multiplatform, kotlin-multiplatform-library, kotlin-multiplatform-mobile, kotlin-native
License
Apache-2.0

Documentation

secure-random

badge-license badge-latest-release

badge-kotlin

badge-platform-android badge-platform-jvm badge-platform-js badge-platform-js-node badge-platform-linux badge-platform-macos badge-platform-ios badge-platform-tvos badge-platform-watchos badge-platform-windows badge-support-android-native badge-support-apple-silicon badge-support-js-ir badge-support-linux-arm badge-support-linux-mips

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