Search packages, repositories and app categories

Package detailsv2.0.0

hashids2

Hashids is small library to generate YouTube-like ids from numbers. Use Hashids when you do not want to expose your database ids to the user.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
9.6K
Likes
29
Pub points
140

Install package

flutter pub add hashids2

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

Hashids2 is a lightweight Dart package that generates short, unique, and URL-safe IDs from numbers, similar to YouTube's ID format. It's designed to obfuscate database IDs, preventing users from guessing or manipulating sequential identifiers. Ideal for public-facing applications where security through obscurity is beneficial. The library supports multiple platforms including Android, iOS, Web, macOS, Windows, and Linux, making it versatile for cross-platform apps. It uses customizable salt and length settings to ensure uniqueness and control over output format.

Use cases

  • Obfuscating database IDs in URLs
  • Generating short unique identifiers
  • Securing API endpoints from ID enumeration
  • Creating user-friendly shareable links
  • Preventing sequential ID exposure in public APIs

Key features

  • Generates URL-safe strings from numbers
  • Customizable salt and minimum length
  • Cross-platform compatibility
  • Simple integration with Flutter apps
  • Supports both encoding and decoding

Suitable for

  • Web and mobile apps needing secure ID generation
  • Developers wanting to hide database structure
  • Applications with public-facing identifiers
  • Projects requiring simple obfuscation without complex cryptography

Considerations

  • Not suitable for high-security cryptographic needs
  • Requires careful salt management for uniqueness
  • Does not provide encryption or authentication
  • Output length depends on input size and configuration
  • Limited to ID obfuscation, not full data protection

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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.

Categories

Source repository

Projects using this package

No data available yet.