Skip to main content
Version: 2.0.x

Secure Random

The implementation wraps java.crypto.SecureRandom with ZIO bindings. We choose the system-default security Provider.

SecureRandom generates random bytes, and random base64-encoded strings.

Random Strings

Strings generated from SecureRandom are base-64 encoded. This encoding means that generated strings are longer than the supplied entropyBytes.

import zio.crypto.random.SecureRandom
SecureRandom.nextString(entropyBytes = 8)

Random Bytes

import zio.crypto.random.SecureRandom

Runnable Example

import zio.crypto.random.SecureRandom

object Example extends zio.App {
override def run(args: List[String]) = (for {
randBytes <- SecureRandom.nextBytes(5)
randString <- SecureRandom.nextString(5)
} yield ExitCode.success)