secure_nonce 1.0.0 copy "secure_nonce: ^1.0.0" to clipboard
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.

example/secure_nonce_example.dart

// ignore_for_file: avoid_print
library;

import 'package:secure_nonce/secure_nonce.dart';

void main() {
  final nonce = SecureNonce();

  print('secure_nonce examples\n');

  // Basic hex nonce - most common use case
  print('Hex nonces:');
  print('  16 bytes: ${nonce.generate(16)}');
  print('  32 bytes: ${nonce.generate(32)}');
  print('');

  // Raw bytes for crypto operations
  print('Raw bytes (for encryption/hashing):');
  final iv = nonce.generateBytes(16);
  print('  AES IV: $iv');
  print('');

  // Base64 for APIs and headers
  print('Base64 (for headers/cookies):');
  print('  Token: ${nonce.generateBase64(24)}');
  print('');

  // URL-safe base64 - no encoding needed in URLs
  print('URL-safe base64:');
  final token = nonce.generateBase64Url(24);
  print('  https://example.com/verify?token=$token');
  print('');

  // Alphanumeric for user-facing codes
  print('Alphanumeric (human-readable):');
  print('  Invite code: ${nonce.generateAlphanumeric(8)}');
  print('  Order ID: ${nonce.generateAlphanumeric(12)}');
}
1
likes
160
points
128
downloads

Publisher

unverified uploader

Weekly Downloads

A cryptographically secure nonce generator for Dart. Generate random nonces as hex, bytes, base64, or alphanumeric strings using cryptographically secure random number generation.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on secure_nonce