smart-hash

nechin/smart-hash

Source Code Latest Version Software License Total Downloads

About

A simple hash generator that makes it easy to get a hash for any text.

From Wikipedia:

A hash function is any function that can be used to map data of arbitrary size to fixed-size values. The values returned by a hash function are called hash values, hash codes, digests, or simply hashes. The values are used to index a fixed-size table called a hash table. Use of a hash function to index a hash table is called hashing or scatter storage addressing.

Installation

The preferred method of installation is via Packagist and Composer. Run the following command to install the package and add it as a requirement to your project’s composer.json:

composer require nechin/smart-hash

Requirements

PHP 5.4.0

Examples

If no length is specified, the ripemd128 algorithm is used, which will generate a string of 32 hexadecimal digits.

The following hash lengths are available: 8, 16, 32, 40, 48, 56, 64, 80, 96, 128. For each length is used its own optimal algorithm.

It is possible to specify the desired algorithm as the third parameter. Then the second parameter should be false.

<?php
use Nechin\SmartHash\SmartHash;

SmartHash::hash('Hello World');  // 2d02b563447f954eafdc4824a190ddcc
SmartHash::hash('Hello World', 64);  // 32b7b7d2408f9389d77cc00aff3c1529504508e86cdbc78a95c469fc68f80543
SmartHash::hash('Hello World', false, 'sha384'); // 99514329186b2f6ae4a1329e7ee6c610a729636335174ac6b740f9028396fcc803d0e93863a7c3d90f86beee782f4f3f

The nechin/smart-hash library is copyright © Alexander Vitkalov and licensed for use under the MIT License (MIT). Please see LICENSE for more information.