SecretKeyData.random constructor

SecretKeyData.random({
  1. required int length,
  2. Uint8List? bytes,
  3. Random? random,
  4. String? debugLabel,
})

Generates N random bytes.

A description of the random number generator:

  • In browsers, `window.crypto.getRandomValues() is used directly.
  • In other platforms, dart:math Random.secure() is used.

You can give a custom random number generator. This can be useful for deterministic tests.

Example

// Generate 32 random bytes
final key = SecretKey.randomBytes(32);

Implementation

factory SecretKeyData.random({
  required int length,
  Uint8List? bytes,
  Random? random,
  String? debugLabel,
}) {
  return SecretKeyData.randomWithBuffer(
    Uint8List(length),
    random: random,
    debugLabel: debugLabel,
  );
}