2017 © Pedro Peláez
 

library hash

Introduces HashGenerator class that can be used to register and use different hash algorithms

image

devhelp/hash

Introduces HashGenerator class that can be used to register and use different hash algorithms

  • Thursday, September 25, 2014
  • by devhelp
  • Repository
  • 3 Watchers
  • 0 Stars
  • 28 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Build Status SensioLabsInsight, (*1)

Installation

Composer is preferred to install Devhelp/Hash, please check composer website for more information., (*2)

$ composer require 'devhelp/hash:dev-master'

Purpose

Devhelp/Hash introduces HashGenerator class that can be used to register and use different hash algorithms. It supports all PHP core hash algorithms by default, but you can register custom ones as \Closure or Devhelp\Hash\Algorithm\HashAlgorithmInterface, (*3)

Usage

Using built-in php core algorithms

it uses hash function under the hood, (*4)

$generator = new \Devhelp\Hash\HashGenerator();

$generator->generate('sha256', 'some_data'); // returns hash generated by sha256 algorithm

$generator->generate('sha256', 'some_data', array('raw_output' => true);

Registering custom algorithms

class CustomHashAlgorithm implements \Devhelp\Hash\Algorithm\HashAlgorithmInterface
{
    public function hash($data, array $options = array())
    {
        //...
    }
}

$myAlgorithm = new CustomHashAlgorithm();
$myClosure = function ($data, $options) {
    //...
};

$generator = new \Devhelp\Hash\HashGenerator();

$generator->register('my_algorithm', $myAlgorithm);
$generator->register('my_closure', $myClosure);

$generator->generate('my_algorithm', 'some_data'); //returns hash generated by CustomHashAlgorithm class
$generator->generate('my_closure', 'some_data'); //returns hash generated by $myClosure \Closure

Overriding built-in PHP core algorithms

Only thing to do is to define custom algorithm and register in under the same name as the core algorithm, (*5)

$generator = new \Devhelp\Hash\HashGenerator();

$generator->register('sha512', new CustomHashAlgorithm());

$generator->generate('sha512', $data); //returns hash generated by CustomHashAlgorithm class

Credits

Brought to you by : Devhelp.pl, (*6)

The Versions

25/09 2014

dev-master

9999999-dev http://devhelp.pl

Introduces HashGenerator class that can be used to register and use different hash algorithms

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Paweł Barański
by devhelp.pl

hash

25/09 2014

1.0

1.0.0.0 http://devhelp.pl

Introduces HashGenerator class that can be used to register and use different hash algorithms

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Paweł Barański
by devhelp.pl

hash