PHP Classes
elePHPant
Icontem

tinyID: Shorten and obfuscate identifier strings

Recommend this page to a friend!

  Author Author  
Name: Kacper Rowinski <contact>
Classes: 9 packages by
Country: Poland Poland
Innovation award
Innovation award
Nominee: 3x


  Detailed description   Download Download .zip .tar.gz  
This package can shorten and obfuscate identifier strings.

It takes a given key string made of unique Unicode characters that will work as dictionary.

The package can encode another string using the key string as dictionary so the resulting encoded string is made only of characters of the key string, resulting in a shorter string.

It can also take a previously encoded string and reverts to the original string using the same key.


Details

Shorten and obfuscate IDs

Build Status

SYNOPSIS

    use TinyID\TinyID;
    
    include __DIR__ . '/../vendor/autoload.php';
    
    // dictionary must consist of at least two UNIQUE unicode characters.
    $tinyId = new TinyID('2BjLhRduC6Tb8Q5cEk9oxnFaWUDpOlGAgwYzNre7tI4yqPvXm0KSV1fJs3ZiHM');
    
    var_dump($tinyId->encode('48888851145')); // will print 1FN7Ab
    var_dump($tinyId->decode('1FN7Ab')); // will print 48888851145

DESCRIPTION

Using real IDs in various places - such as GET links or API payload - is generally a bad idea:

  • It may reveal some sensitive informations about your business, such as growth rate or amount of customers.
  • If someone finds unprotected resource link, where you forgot to check if passed resource ID really belongs to currently logged-in user, he will be able to steal all of your data really fast just by incrementing ID in links.
  • Big numbers may cause overflows in places where length is limited, such as SMS messages.

With the help of this module you can shorten and obfuscate your IDs at the same time.

METHODS

new TidyID('qwerty')

Key must consist of at least two *unique* unicode characters.

The longer the dictionary - the shorter encoded ID.

Encoded ID will be made exclusively out of characters from the key. This very useful property allows to adapt your encoding to the environment. For example in SMS messages you may restrict key to US ASCII to avoid available length reduction caused by conversion to GSM 03.38 charset. Or if you want to use such ID as file/directory name in case insensitive filesystem you may want to use only lowercase letters in the key.

encode(123)

Encode positive integer into a string.

Note that leading 0s are not preserved, encode(123) is the same as encode(00123).

Used algorithm is a base to the length of the key conversion that maps to distinct permutation of characters. Do not consider it a strong encryption, but if you have secret and long and well shuffled key it is almost impossible to reverse-engineer real ID.

decode('rer')

Decode string back into a positive integer.

TRICKS

If you provide sequential characters in key you can convert your numbers to some weird numeric systems, for example base18:

    var_dump((new TinyID('0123456789ABCDEFGH'))->encode(48888851145)); // '47F709HFF'

Or you can go wild just for the fun of it.

    var_dump((new TinyID('????????????????????????????????????????????????????????????????'))->encode(48888851145)); // '??????'

OTHER IMPLEMENTATIONS

It's based on great work of bbkr and his project https://github.com/bbkr/TinyID

All examples are in example dir.


  Classes of Kacper Rowinski  >  tinyID  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: tinyID
Base name: tinyid
Description: Shorten and obfuscate identifier strings
Version: 1.0
PHP version: 5.6
License: MIT/X Consortium License
 
  Groups   Applications   Files Files  

  Groups  
Group folder image Algorithms Numerical and statistical algorithms View top rated classes
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Cryptography Encrypting, decrypting and hashing data View top rated classes
Group folder image Text processing Manipulating and validating text data View top rated classes


  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Files folder imageexample (1 file)
Files folder imagesrc (1 directory)
Files folder imagetests (1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  example  
File Role Description
  Accessible without login Plain text file example.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imageTinyID (1 file)

  Files folder image Files  /  src  /  TinyID  
File Role Description
  Plain text file TinyID.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageUnit (1 file)

  Files folder image Files  /  tests  /  Unit  
File Role Description
  Plain text file TinyIDTest.php Class Class source

Download Download all files: tinyid.tar.gz tinyid.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.