yzalis/id-obfuscator

This package is abandoned and no longer maintained. No replacement package was suggested.

An efficient reversible ID obfuscator originaly based on base 62 encoding.

1.0.0 2015-05-13 19:06 UTC

This package is not auto-updated.

Last update: 2021-02-12 12:03:47 UTC


README

IdObfuscator is a library which helps you to hide your original IDs. The library helps you to encode and decode these IDs

SensioLabsInsight

Basic Usage

Instantiate the obfuscator

<?php

// create a new IdObfuscator instance
$idObfuscator = new \IdObfuscator\IdObfuscator();

Then you can encode your id and decode the generated hash.

$hash = $idObfuscator->encode(10); // $hash contain "A"
$id = $idObfuscator->decode('A'); // $id contain "10"

Here are some examples with the default set:

10 <=> 'A'
35 <=> 'Z'
36 <=> 'a'
61 <=> 'z'
62 <=> '10'
63 <=> '11'
134 <=> '2A'
3843 <=> 'zz'
3844 <=> '100'
144513 <=> 'bar'
160754 <=> 'foo'
238327 <=> 'zzz'
238328 <=> '1000'

Custom set

By default, the library use the following characters set to encode and decode. 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

You can use the static method randomizeDefaultSet to shuffle the default set.

$myRandomSet = IdObfuscator::randomizeDefaultSet();

Or you can also use you own custom set.

$idObfuscator = new IdObfuscator('cusTOMS3t');
$idObfuscator->encode(1); // will return "c";
$idObfuscator->decode('t'); // will return "9";

Unit Tests

To run unit tests, you'll need cURL and a set of dependencies you can install using Composer:

curl -sS https://getcomposer.org/installer | php
php composer.phar install

Once installed, just launch the following command:

./vendor/bin/phpunit

You're done.

Credits

License

IdObfuscator is released under the MIT License. See the bundled LICENSE file for details.