newKey top-level property

String get newKey

Returns a new random 32-character key ([0-9a-zA-Z]), generated with a cryptographically secure random source. Suitable as a text primary key.

Implementation

String get newKey {
  const String alphabet =
      '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  final Random rng = Random.secure();
  final StringBuffer buffer = StringBuffer();
  for (int i = 0; i < 32; i++) {
    buffer.write(alphabet[rng.nextInt(alphabet.length)]);
  }
  return buffer.toString();
}