secureRandomBytes static method

Uint8List secureRandomBytes(
  1. int length
)

Generate a Uint8List of random bytes of size length suitable for cryptographic use.

Implementation

static Uint8List secureRandomBytes(final int length) {
  final Random random = Random.secure();
  final Uint8List bytes = Uint8List(length);
  for (int i = 0; i < length; i++) {
    bytes[i] = random.nextInt(256);
  }
  return bytes;
}