PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Martin Latter   PHP Random Bytes   README.md   Download  
File: README.md
Role: Auxiliary data
Content type: text/markdown
Description: Documentation
Class: PHP Random Bytes
Generate cryptographically strong random bytes
Author: By
Last change: revise README.md
Date: 4 years ago
Size: 1,263 bytes
 

Contents

Class file image Download

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.