2017 © Pedro Peláez
 

library random-lib

A Library For Generating Secure Random Numbers

image

paragonie/random-lib

A Library For Generating Secure Random Numbers

  • Wednesday, December 27, 2017
  • by paragonie-scott
  • Repository
  • 4 Watchers
  • 26 Stars
  • 24,780 Installations
  • PHP
  • 7 Dependents
  • 1 Suggesters
  • 105 Forks
  • 0 Open issues
  • 9 Versions
  • 46 % Grown

The README.md

RandomLib

Build Status Latest Stable Version Latest Unstable Version License, (*1)

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

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

Note: This is a fork of Anthony Ferrara's RandomLib, maintained by Paragon Initiative Enterprises., (*4)

Install

Via Composer, (*5)

$ composer require paragonie/random-lib

Usage

Factory

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

$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., (*7)

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

$generator = $factory->getMediumStrengthGenerator();

$factory->getLowStrengthGenerator()

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

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., (*10)

$factory->getMediumStrengthGenerator()

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

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, (*12)

$factory->getHighStrengthGenerator()

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

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., (*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 #phpc channel on irc.freenode.net., (*24)

Security Vulnerabilities

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

The Versions

27/12 2017

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/10 2017

v2.0.0

2.0.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

06/10 2017

v2.0.0-rc1

2.0.0.0-RC1 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

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

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