2017 © Pedro Peláez
 

library idhash

A reversible (integer) ID obfuscator

image

moccalotto/idhash

A reversible (integer) ID obfuscator

  • Sunday, July 29, 2018
  • by moccalotto
  • Repository
  • 1 Watchers
  • 0 Stars
  • 167 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

IdHash

Build Status, (*1)

A reversible (integer) ID obfuscator, (*2)

Create hashes like the ones used by imgur, pastebin, youtube, etc., (*3)

Default keyspace is the standard base62 keyspace., (*4)

Installation

To add this package as a local, per-project dependency to your project, simply add a dependency on moccalotto/idhash to your project's composer.json file like so:, (*5)

{
    "require": {
        "moccalotto/idhash": "~0.9"
    }
}

Alternatively simply call composer require moccalotto/idhash, (*6)

<?php

use Moccalotto\IdHash\IntHasher;
use Moccalotto\IdHash\StringKey;
use Moccalotto\IdHash\RandomKeyFactory;

require 'vendor/autoload.php';

// you can generate a randomized base62 key by running bin/random_key
$keyspace = '8w2JUNlFLxfuCXbjkOmBizsWHG9Ep5n4Pd70yZg63vAerQVTMIRhS1DKqocaYt';

// Create a key shuffler
// This is roughly the same as $key = str_shuffle($keyspace),
// but it guarantees that the output keyspace is different from the input keyspace
// It also ensures that we squash duplicate characters
$key_generator = new RandomKeyFactory($keyspace);

// generate a random key
$key = $key_generator->key();

// initialize a new IntHasher
$IntHasher = new IntHasher($key);

// generate new input value
$input_int = mt_rand();

// encode the integer into a hash
$hash_str = $IntHasher->intToHash($input_int);

// decode the hash into an integer
$output_int = $IntHasher->hashToInt($hash_str);

// print the process values to screen
printf('The generated key:  %s%s', $key->keyString(), PHP_EOL);
printf('Number to encode:   %d%s', $input_int, PHP_EOL);
printf('The encoded hash:   %s%s', $hash_str, PHP_EOL);
printf('Decoded number:     %s%s', $output_int, PHP_EOL);
printf('Success:            %s%s', $input_int === $output_int ? 'Yes' : 'NO!', PHP_EOL);

die($input_int !== $output_int);

The Versions

29/07 2018

dev-master

9999999-dev

A reversible (integer) ID obfuscator

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

uuid hashid base64 base62

29/07 2018

1.0.0

1.0.0.0

A reversible (integer) ID obfuscator

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

uuid hashid base64 base62

11/11 2016

0.9.0

0.9.0.0

A reversible (integer) ID obfuscator

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

uuid hashid base64 base62

03/12 2015

0.8

0.8.0.0

A reversible (integer) ID obfuscator

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

uuid hashid base64 base62

02/12 2015

0.5

0.5.0.0

A reversible (integer) ID obfuscator

  Sources   Download

MIT

The Requires

  • php >=5.6

 

uuid hashid base64 base62

30/11 2015

0.2

0.2.0.0

A reversible (integer) ID obfuscator

  Sources   Download

MIT

The Requires

  • php >=5.6

 

uuid hashid base64 base62