secureRandomBytes

expect fun secureRandomBytes(size: Int): ByteArray

Generates cryptographically secure random bytes.

Uses platform-specific CSPRNG:

  • JVM: java.security.SecureRandom

  • JS: crypto.getRandomValues

  • Native: libsodium randombytes_buf

Return

ByteArray of cryptographically secure random bytes

Parameters

size

Number of random bytes to generate (must be positive)

Throws

if size is not positive

actual fun secureRandomBytes(size: Int): ByteArray

Generates cryptographically secure random bytes using Web Crypto API.

Uses crypto.getRandomValues() which is available in all modern browsers and Node.js. This is the recommended way to generate cryptographic randomness in JavaScript environments.

actual fun secureRandomBytes(size: Int): ByteArray

Generates cryptographically secure random bytes using java.security.SecureRandom.

actual fun secureRandomBytes(size: Int): ByteArray

Generates cryptographically secure random bytes using libsodium.

Uses randombytes_buf() which is backed by the system CSPRNG (arc4random_buf on Apple platforms).