secure_nonce 1.0.0
secure_nonce: ^1.0.0 copied to clipboard
A cryptographically secure nonce generator for Dart. Generate random nonces as hex, bytes, base64, or alphanumeric strings using cryptographically secure random number generation.
secure_nonce #
A simple nonce generator for Dart using cryptographically secure randomness.
Installation #
dependencies:
secure_nonce: ^1.0.0
Usage #
import 'package:secure_nonce/secure_nonce.dart';
void main() {
final nonce = SecureNonce();
// hex string (32 chars from 16 bytes)
final token = nonce.generate(16);
// raw bytes
final iv = nonce.generateBytes(16);
// base64 encoded
final key = nonce.generateBase64(32);
// url-safe base64
final urlToken = nonce.generateBase64Url(24);
// alphanumeric only
final code = nonce.generateAlphanumeric(8);
}
Methods #
| Method | Returns |
|---|---|
generate(n) |
hex string, n*2 chars |
generateBytes(n) |
Uint8List, n bytes |
generateBase64(n) |
base64 from n bytes |
generateBase64Url(n) |
url-safe base64 |
generateAlphanumeric(n) |
n alphanumeric chars |
Security #
Uses Random.secure() which pulls from the OS cryptographic RNG (/dev/urandom on Linux, CryptGenRandom on Windows).
License #
MIT