PHP Random Bytes: Generate cryptographically strong random bytes

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-02-16 (8 months ago) RSS 2.0 feedNot enough user ratingsTotal: 170 All time: 8,632 This week: 372Up
Version License PHP version Categories
random-bytes 0.14GNU General Publi...5.4PHP 5, Cryptography, Security
Description Author

This class can generate cryptographically strong random bytes.

It can generate a string of bytes with random values using a given method.

Currently it can use either methods using mcrypt, OpenSSL, or /dev/urandom on Linux. The default is to use mcrypt.

Innovation Award
PHP Programming Innovation award nominee
May 2015
Number 5


Prize: One downloadable e-book of choice by O'Reilly
Many cryptography algorithms use random numbers to make it harder to break the security measures based on those algorithms.

There are many pseudo-random number generators that can be used to generate cryptographically strong data values.

This class can generate random streams of bytes that are more secure to use in cryptography applications by either using /dev/random on Linux, OpenSSL or mcrypt libraries.

Manuel Lemos
Picture of Martin Latter
  Performance   Level  
Name: Martin Latter is available for providing paid consulting. Contact Martin Latter .
Classes: 7 packages by
Country: United Kingdom
Age: ???
All time rank: 147264 in United Kingdom
Week rank: 79 Up5 in United Kingdom Up
Innovation award
Innovation award
Nominee: 4x

Details

Random Bytes

Generate cryptographically-strong random bytes.

Purpose

Create random bytes – as cryptographically-strong as possible – from available sources of entropy, and display in different output formats.

Crypto Sources

  • Linux/Unix: OpenSSL, `random_bytes()`, /dev/urandom
  • Windows: OpenSSL, `random_bytes()`

Random Bytes Definitions:

  • openssl
  • random_bytes
  • urandom

Usage

Prototype

    array RandomBytes::generate(int $length, string $source);

Example

    require('randombytes.class.php');
    use Tinram\RandomBytes\RandomBytes;
    $aData = RandomBytes::generate(32, 'openssl');
    var_dump($aData);

Details

The random bytes generated are only as good as the underlying entropy generator of the OS.

Linux's /dev/urandom entropy source is a non-blocking generator 'suitable for most cryptographic purposes'. (/dev/random, being blocking, isn't suitable for this script.)

OpenBSD and FreeBSD have non-blocking /dev/random implementations.

The random_bytes() function was added to PHP version 7.0

License

Random Bytes is released under the GPL v.3.

  Files folder image Files  
File Role Description
Files folder imageclasses (1 file)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file randombytes_example.php Example Example script
Accessible without login Plain text file randombytes_example2.php Aux. Auxiliary script
Accessible without login Plain text file README.md Data Documentation

  Files folder image Files  /  classes  
File Role Description
  Plain text file randombytes.class.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:170
This week:0
All time:8,632
This week:372Up

For more information send a message to info at phpclasses dot org.