2017 © Pedro Peláez
 

library token

image

projx-io/token

  • Thursday, May 19, 2016
  • by projx
  • Repository
  • 0 Watchers
  • 1 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

Tokenizer

http://github.com/projx-io/token.git, (*2)

Install

composer: composer require projx-io/token, (*3)

Usage

  // The key used to encrypt the token. This ideally would not be random, and would be saved somewhere.
  $key = openssl_random_pseudo_bytes(32);           

  $encoderBuilder = (new EncoderBuilder())
      ->validateEncode(new IsArrayValidation())     // 1. add encode validation encoder
      ->pack()                                      // 2. add pack encoder
      ->compress()                                  // 3. add gzip encoder
      ->encrypt($key)                               // 4. add encryption encoder
      ->base64()                                    // 5. add base64 encoder
      ->validateDecode(new IsStringValidation());   // 6. add decode validation encoder

  // The chain performs the following:
  // 
  // Encoding (read chain from top to bottom):
  // 1. verify value is an array 
  // 2. convert array into binary string 
  // 3. gzip deflate
  // 4. encrypt with key and random vector (which is prepended to value to be read when decoding)
  // 5. encode binary into string via base64 
  // 
  // Decoding (read chain from bottom to top):
  // 6. verify that value is a string
  // 5. decode string into binary via base64 
  // 4. decrypt binary with key and parsed vector
  // 3. gzip inflate
  // 2. parse binary string into array 

  // The following builds the packer, which is an encoder that uses pack() to convert an array into a binary string.
  // With the following
  $encoderBuilder->packer()
      ->uint32BE('created')   // 1. encoding: expect 32bit int; decoding: name the int 'created'
      ->uint32BE('app_id')    // 2. encoding: expect 32bit int; decoding: name the int 'app_id'
      ->uint32BE('user_id');  // 3. encoding: expect 32bit int; decoding: name the int 'user_id'

  $encoder = $encoderBuilder->build();

  $token = $encoder->encodeToken([strtotime('now'), 5, 16]);
  echo json_encode($token) . "\n";
  // "9zxpVdE3QnDfAvTVcktpdz7R5A18rHP\/3ZXX9BaI"

  $decoded = $encoder->decodeToken($token);
  echo json_encode($decoded) . "\n";
  // {"created":1455760831,"app_id":5,"user_id":16}

The Versions

19/05 2016

dev-master

9999999-dev

  Sources   Download

The Requires

 

The Development Requires

by Terrence Howard

19/05 2016

1.3

1.3.0.0

  Sources   Download

The Requires

 

The Development Requires

by Terrence Howard

19/05 2016

dev-crypto-binary-output

dev-crypto-binary-output

  Sources   Download

The Requires

 

The Development Requires

by Terrence Howard

19/05 2016

1.2

1.2.0.0

  Sources   Download

The Requires

 

The Development Requires

by Terrence Howard

19/05 2016

dev-upgrade-defuse/php-encryption

dev-upgrade-defuse/php-encryption

  Sources   Download

The Requires

 

The Development Requires

by Terrence Howard

18/02 2016

1.1

1.1.0.0

  Sources   Download

The Requires

 

The Development Requires

by Terrence Howard

18/02 2016

1.0

1.0.0.0

  Sources   Download

The Development Requires

by Terrence Howard