genDart method

String genDart({
  1. int len = 16,
})

Generate cryptographically-secure random string using Dart math.random. The string is encoded using base64. Thus, this is for use with encoded classes.

This is less secure than Fortuna, but faster. It can be used for IVs and salts, but never for keys.

Defaults to length 16.

Implementation

String genDart({int len = 16}) {
  dart ??= Random.secure();
  var bytes = List<int>.generate(len, (i) => dart!.nextInt(256));
  return base64.encode(bytes);
}