SecureIdGenerator class

Cryptographically-secure variant of IdGenerator.

Every method uses Random.secure() — backed by the operating-system CSPRNG — making output suitable for tokens, session keys, API keys, password-reset links, and other security-sensitive values.

For non-security IDs (primary keys, slugs, display codes) prefer IdGenerator: it is faster and avoids draining OS entropy unnecessarily.

Constant-time comparison: always compare tokens with safeEqual rather than == to prevent timing-based side-channel attacks.

Constructors

SecureIdGenerator()

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

nanoid({int size = 21, String? alphabet}) → String
Generates a cryptographically random nanoid-style ID.
prefixed(String prefix, {int length = 16}) → String
Generates a cryptographically random prefixed ID (prefix_xxxx). Suitable for API keys and scoped resource tokens.
randomString({int length = 8, bool useLetters = true, bool useNumbers = true, bool useSymbols = true}) → String
Generates a cryptographically random string with configurable character sets. Suitable for passwords, OTPs, and secret codes.
safeEqual(String a, String b) → bool
Compares two strings in constant time to prevent timing-based attacks.
shortId({int length = 8}) → String
Generates a cryptographically random URL-safe alphanumeric ID. Suitable for invite codes and one-time tokens.
ulid() → String
Generates a ULID whose random portion uses Random.secure().
ulidMonotonic() → String
Generates a ULID that sorts after every ULID this generator produced before it, using Random.secure() for the initial suffix of each millisecond.
uuidV4Like() → String
Generates a UUID v4-shaped ID whose bits are from Random.secure().