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

插件详情v2.0.0

hashids2

Hashids 是一个小型库,可将数字生成类似 YouTube 的 ID。当您不希望向用户暴露数据库 ID 时,请使用 Hashids。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
9600
喜欢数
29
Pub 分数
140

安装插件

flutter pub add hashids2

插件介绍

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

Hashids2 是一个轻量级的 Dart 包,可将数字转换为短小、唯一且 URL 安全的 ID,类似于 YouTube 的 ID 格式。它旨在混淆数据库 ID,防止用户猜测或操纵顺序标识符。适用于需要通过隐蔽性增强安全性的公开应用。该库支持多种平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,使其在跨平台应用中具有高度灵活性。它使用可自定义的盐值和长度设置,以确保唯一性并控制输出格式。

适合场景

  • 在URL中混淆数据库ID
  • 生成短的唯一标识符
  • 防止API端点的ID枚举
  • 创建用户友好的可分享链接
  • 防止公共 API 中的顺序 ID 暴露

主要特点

  • 从数字生成 URL 安全的字符串
  • 可自定义的盐值和最小长度
  • 跨平台兼容性
  • 与 Flutter 应用的简单集成
  • 支持编码和解码

适合对象

  • 需要安全ID生成的Web和移动应用
  • 想要隐藏数据库结构的开发人员
  • 具有面向公众的标识符的应用程序
  • 需要简单混淆而无需复杂加密的项目

使用建议

  • 不适合高安全性加密需求
  • 需要仔细管理盐以确保唯一性
  • 不提供加密或身份验证
  • 输出长度取决于输入大小和配置
  • 仅限ID混淆,不提供完整数据保护

原始 README

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

Hashids2

Build Status Coverage Status pub package

A Dart class to generate YouTube-like hashes from one or many numbers.

Ported from javascript hashids.js by Ivan Akimov

What is it?

Hashids (Hash ID's) creates short, unique, decryptable hashes from unsigned (long) integers.

This algorithm tries to satisfy the following requirements:

  1. Hashes must be unique and decryptable.
  2. They should be able to contain more than one integer (so you can use them in complex or clustered systems).
  3. You should be able to specify minimum hash length.
  4. Hashes should not contain basic English curse words (since they are meant to appear in public places - like the URL).

Instead of showing items as 1, 2, or 3, you could show them as U6dc, u87U, and HMou. You don't have to store these hashes in the database, but can encrypt + decrypt on the fly.

All (long) integers need to be greater than or equal to zero.

Usage

Import the package

Follow instructions from Pub.

Encrypting
final hashids = HashIds();
final fromNumber = hashids.encode(42);
final fromList = hashids.encode([1,2,3]);
final fromString = hashids.encode('42');
Decrypting
final hashids = HashIds();
final number = hashids.decode(fromNumber); // [42]
final list = hashids.decode(fromList); // [1,2,3]
final string = hashids.decode(fromString); // [42]

License

MIT License. See the LICENSE file. You can use Hashids in open source projects and commercial products. Don't break the Internet. Kthxbye.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。