搜索插件、代码仓与 APP 分类

插件详情v1.2.0

nonce

Nonce 包含一个静态生成器,用于生成随机的字母数字字符串,并且可以构造为包含生成字符串的对象。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
6.1万
喜欢数
12
Pub 分数
150

安装插件

flutter pub add nonce

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

nonce 包提供了一个简单的静态生成器,用于创建随机的字母数字字符串,适用于在安全敏感环境中生成唯一标识符。它既可以作为静态工具使用,也可以实例化为持有已生成随机数的对象。该包专为测试、加密和权限系统设计,确保不可预测性和唯一性。该包具有跨平台特性,支持 Android、iOS、Web、macOS、Windows 和 Linux,适用于各种应用环境。

适合场景

  • 生成用于身份验证的唯一令牌
  • 创建具有保证唯一性的测试数据
  • 支持需要随机数的加密操作
  • 防止网络请求中的重放攻击
  • 保护会话管理

主要特点

  • 用于生成随机字母数字字符串的静态生成器
  • 基于对象的随机数实例化
  • 跨平台兼容性
  • 简单 API,快速集成
  • 专为安全和测试用例设计

适合对象

  • 开发安全应用程序的开发者
  • 测试工程师需要唯一标识符
  • 涉及身份验证或加密的项目
  • 需要防重放保护的应用程序
  • Flutter 应用针对多个平台

使用建议

  • 不适用于高熵加密密钥生成
  • 如果需要确定性行为,请确保正确播种
  • 验证使用上下文是否符合安全要求
  • 在敏感场景中避免重用生成的随机数
  • 依赖于 Dart 的随机数生成器,在所有环境中可能不具备加密强度

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

nonce

pub package

[Nonce] contains a static generator that generates random alphanumeric strings, and can be constructed as an object containing a generated string.

Usage

import 'package:nonce/nonce.dart';

Generator

The static method [generate] can be used to generate random alphanumeric strings.

[generate] has 2 optional parameters, [length] which defines how many characters to generate, and [random] which allows you provide a [Random] to use to generate the characters.

// Generate a string 32 characters long.
print(Nonce.generate()); // Osp54up7WU6P3U97Jz92p9j892n9LP7z

// Generate a string 64 characters long.
print(Nonce.generate(64)); // LDwpr1H74qm894jbd15Lj63wF5RUL07r4L9XOY7zVMz7fLbBCXa68Y6oPw0N9XgV

// Generate a nonce using a secure [Random].
print(Nonce.generate(32, Random.secure()));

generate() does not rely on Base64 encoding, instead it generates ASCII character codes directly.

Constructors

[Nonce]'s default constructor constructs a [Nonce] of the specified length; 32 characters by default.

Nonce();
Nonce(64);
unique

[Nonce]'s [unique] constructor references a global set of every nonce generated by it, and ensures that every nonce returned by it is unique.

Nonce.unique();
Nonce.unique(64);
secure

[Nonce]'s [secure] constructor generates a unique nonce using a secure [Random].

Nonce.secure();
Nonce.secure(64);
key

The [key] constructor is shorthand to generate a [unique] nonce 16 characters in length.

Nonce.key(); // Osp54up7WU6P3U97

所属分类

源码仓库

使用此插件的项目

暂无相关数据。