2017 © Pedro Peláez
 

library random-lib

A Library For Generating Secure Random Numbers

image

ircmaxell/random-lib

A Library For Generating Secure Random Numbers

  • Wednesday, September 7, 2016
  • by ircmaxell
  • Repository
  • 46 Watchers
  • 712 Stars
  • 3,200,172 Installations
  • PHP
  • 121 Dependents
  • 9 Suggesters
  • 105 Forks
  • 18 Open issues
  • 7 Versions
  • 7 % Grown

The README.md

RandomLib

Build Status, (*1)

A library for generating random numbers and strings of various strengths., (*2)

This library is useful in security contexts., (*3)

Install

Via Composer, (*4)

$ composer require ircmaxell/random-lib

Usage

Factory

A factory is used to get generators of varying strength:, (*5)

$factory = new RandomLib\Factory;
$generator = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM));

A factory can be configured with additional mixers and sources but can be used out of the box to create both medium and low strength generators., (*6)

Convenience methods are provided for creating high, medium, and low strength generators. Example:, (*7)

$generator = $factory->getMediumStrengthGenerator();

$factory->getLowStrengthGenerator()

Convenience method to get a low strength random number generator., (*8)

Low Strength should be used anywhere that random strings are needed in a non-cryptographical setting. They are not strong enough to be used as keys or salts. They are however useful for one-time use tokens., (*9)

$factory->getMediumStrengthGenerator()

Convenience method to get a medium strength random number generator., (*10)

Medium Strength should be used for most needs of a cryptographic nature. They are strong enough to be used as keys and salts. However, they do take some time and resources to generate, so they should not be over-used, (*11)

$factory->getHighStrengthGenerator()

Convenience method to get a high strength random number generator., (*12)

High Strength keys should ONLY be used for generating extremely strong cryptographic keys. Generating them is very resource intensive and may take several minutes or more depending on the requested size., (*13)

There are currently no mixers shipped with this package that are capable of creating a high space generator. This will not work out of the box!, (*14)

Generator

A generator is used to generate random numbers and strings., (*15)

Example:, (*16)

// Generate a random string that is 32 bytes in length.
$bytes = $generator->generate(32);

// Generate a whole number between 5 and 15.
$randomInt = $generator->generateInt(5, 15);

// Generate a 32 character string that only contains the letters
// 'a', 'b', 'c', 'd', 'e', and 'f'.
$randomString = $generator->generateString(32, 'abcdef');

$generator->generate($size)

Generate a random byte string of the requested size., (*17)

$generator->generateInt($min = 0, $max = PHP_INT_MAX)

Generate a random integer with the given range. If range ($max - $min) is zero, $max will be used., (*18)

$generator->generateString($length, $characters = '')

Generate a random string of specified length., (*19)

This uses the supplied character list for generating the new result string. The list of characters should be specified as a string containing each allowed character., (*20)

If no character list is specified, the following list of characters is used:, (*21)

0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/

Examples:, (*22)

// Give the character list 'abcdef':
print $generator->generateString(32, 'abcdef')."\n";

// One would expect to receive output that only contained those
// characters:
//
// adaeabecfbddcdaeedaedfbbcdccccfe
// adfbfdbfddadbfcbbefebcacbefafffa
// ceeadbcabecbccacdcaabbdccfadbafe
// abadcffabdcacdbcbafcaecabafcdbbf
// dbdbddacdeaceabfaefcbfafebcacdca

License

MIT, see LICENSE., (*23)

Community

If you have questions or want to help out, join us in the #php.security channel on irc.freenode.net., (*24)

Security Vulnerabilities

If you have found a security issue, please contact the author directly at me@ircmaxell.com., (*25)

The Versions

07/09 2016

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/ircmaxell/RandomLib

A Library For Generating Secure Random Numbers

  Sources   Download

MIT

The Requires

 

The Development Requires

cryptography random random-numbers random-strings

07/09 2016

dev-master

9999999-dev https://github.com/ircmaxell/RandomLib

A Library For Generating Secure Random Numbers

  Sources   Download

MIT

The Requires

 

The Development Requires

cryptography random random-numbers random-strings

07/09 2016

v1.2.0

1.2.0.0 https://github.com/ircmaxell/RandomLib

A Library For Generating Secure Random Numbers

  Sources   Download

MIT

The Requires

 

The Development Requires

cryptography random random-numbers random-strings

15/01 2015

v1.1.0

1.1.0.0 https://github.com/ircmaxell/RandomLib

A Library For Generating Secure Random Numbers

  Sources   Download

MIT

The Requires

 

The Development Requires

cryptography random random-numbers random-strings

01/05 2014

dev-improved_string_presets

dev-improved_string_presets https://github.com/ircmaxell/RandomLib

A Library For Generating Secure Random Numbers

  Sources   Download

MIT

The Requires

 

The Development Requires

cryptography random random-numbers random-strings

11/04 2014

dev-cipher_mixer

dev-cipher_mixer https://github.com/ircmaxell/RandomLib

A Library For Generating Secure Random Numbers

  Sources   Download

MIT

The Requires

 

The Development Requires

cryptography random random-numbers random-strings

30/07 2013

v1.0.0

1.0.0.0 https://github.com/ircmaxell/PHP-RandomLib

A Library For Generating Secure Random Numbers

  Sources   Download

MIT

The Requires

 

The Development Requires

  • mikey179/vfsstream 1.1.*

cryptography random random-numbers random-strings