hashids2 1.0.2 hashids2: ^1.0.2 copied to clipboard
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.
Hashids2 #
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:
- Hashes must be unique and decryptable.
- They should be able to contain more than one integer (so you can use them in complex or clustered systems).
- You should be able to specify minimum hash length.
- 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
Add to the pubspec.yaml
dependencies:y
hashids2: ^1.0.1
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 #
See the LICENSE
file.