generateSerialNumberBigIntPlatform static method
Gera serial com RNG da plataforma (Web Crypto no navegador).
Implementation
static BigInt generateSerialNumberBigIntPlatform({int bytes = 16}) {
if (bytes < 4 || bytes > 20) {
throw RangeError.range(bytes, 4, 20, 'bytes');
}
final Uint8List serialBytes = _platformCrypto.randomBytes(bytes);
serialBytes[0] = serialBytes[0] & 0x7F;
serialBytes[serialBytes.length - 1] |= 0x01;
BigInt serial = BigInt.zero;
for (final int b in serialBytes) {
serial = (serial << 8) | BigInt.from(b);
}
return serial == BigInt.zero ? BigInt.one : serial;
}