2017 © Pedro Peláez
 

library random

Random data generator for PHP

image

rych/random

Random data generator for PHP

  • Wednesday, July 1, 2015
  • by rchouinard
  • Repository
  • 2 Watchers
  • 13 Stars
  • 141,534 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 5 Forks
  • 3 Open issues
  • 3 Versions
  • 8 % Grown

The README.md

Rych Random Data Library

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-coveralls] Quality Score ![Total Downloads][ico-downloads], (*1)

This library aims to provide a clean interface to generating cryptographically secure random data in PHP 5.3+., (*2)

Install

Via Composer, (*3)

``` bash $ composer require rych/random, (*4)



## Usage The library is easy to get up and running quickly. The best source of random data available for your platform will be automatically selected and configured. ```php <?php $random = new Rych\Random\Random(); // Generate a 16-byte string of random raw data $randomBytes = $random->getRandomBytes(16); // Get a random integer between 1 and 100 $randomNumber = $random->getRandomInteger(1, 100); // Get a random 8-character string using the // character set A-Za-z0-9./ $randomString = $random->getRandomString(8);

If you prefer your random bytes delivered in hex format, we can do that too:, (*5)

<?php

$encoder = new Rych\Random\Encoder\HexEncoder();
$random = new Rych\Random\Random();
$random->setEncoder($encoder);

// Generate a 16-byte string of random raw data,
// encoded as a 32-character hex string
$randomBytes = $random->getRandomBytes(16);

Generators

The library provides support for several CSPRNGs. The generator factory class Rych\Random\Generator\GeneratorFactory can be used to automatically discover and select the best available option for the current platform., (*6)

MCrypt (Rych\Random\Generator\MCryptGenerator)

MCrypt provides an interface to standard operating system CSPRNGs through the mcrypt_create_iv() function. On Windows systems, this function will use the Windows CryptoAPI, while other operating systems will read from /dev/urandom. This backend requires PHP's MCrypt extension to be enabled., (*7)

This is the preferred backend, and will be selected by default if it is available., (*8)

OpenSSL (Rych\Random\Generator\OpenSSLGenerator)

OpenSSL provides a CSPRNG through the openssl_random_pseudo_bytes() function. Support for this backend requires that PHP's OpenSSL extension be available. Windows servers also have the requirement of running PHP versions >= 5.3.7 due to a bug in the PHP OpenSSL implementation which could cause the function to perform slowly or even hang., (*9)

The OpenSSL backend is the second preferred backend, and will be selected if it is available., (*10)

CAPICOM (Rych\Random\Generator\CapicomGenerator)

Although Microsoft has deprecated the CAPICOM interface, the library currently supports the old interface. Support requires running on a Windows server with the COM extension enabled., (*11)

It should be noted that the MCrypt backend, if available, will use the newer Windows CryptoAPI to access Windows' built-in CSPRNG. The OpenSSL backend will do the same on PHP versions >= 5.4.0., (*12)

As CAPICOM is deprecated, it will only be selected if neither the MCrypt or OpenSSL backends are available on Windows systems., (*13)

/dev/urandom (Rych\Random\Generator\URandomGenerator)

The built-in non-blocking CSPRNG on most non-Windows platforms is supported by this backend. Support requires read-access to /dev/urandom on non-Windows platforms., (*14)

This backend will only be selected if neither the MCrypt or OpenSSL backends are available on non-Windows systems., (*15)

George Argyros' clock drift algorithm (Rych\Random\Generator\ClockDriftGenerator)

Systems which cannot use any of the above backends will use this one. It provides a CSPRNG in pure PHP, although it is pretty slow., (*16)

This backend has no special requirements, and is therefore always available., (*17)

Testing

bash $ vendor/bin/phpunit -c phpunit.dist.xml, (*18)

Security

If you discover any security related issues, please email rchouinard@gmail.com instead of using the issue tracker., (*19)

License

The MIT License (MIT). Please see License File for more information., (*20)

The Versions

01/07 2015

dev-master

9999999-dev https://github.com/rchouinard/rych-random

Random data generator for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.4

 

The Development Requires

cryptography random

29/01 2014

dev-develop

dev-develop https://github.com/rchouinard/rych-random

Random data generator for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.4

 

The Development Requires

cryptography random

12/11 2013

v0.1.0

0.1.0.0 https://github.com/rchouinard/rych-random

Random data generator for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.4

 

The Development Requires

cryptography random