Elgg  Version 1.9
Public Member Functions | Public Attributes | List of all members
ElggCrypto Class Reference

Public Member Functions

 getRandomBytes ($length)
 Generate a string of highly randomized bytes (over the full 8-bit range). More...
 
 getRandomString ($length, $chars=null)
 Generate a random string of specified length. More...
 

Public Attributes

const CHARS_PASSWORD = 'bcdfghjklmnpqrstvwxyz2346789'
 Character set for temp passwords (no risk of embedded profanity/glyphs that look similar) More...
 
const CHARS_HEX = '0123456789abcdef'
 Character set for hexadecimal. More...
 

Detailed Description

Definition at line 10 of file ElggCrypto.php.

Member Function Documentation

ElggCrypto::getRandomBytes (   $length)

Generate a string of highly randomized bytes (over the full 8-bit range).

Parameters
int$lengthNumber of bytes needed
Returns
string Random bytes
Author
George Argyros argyr.nosp@m.os.g.nosp@m.eorge.nosp@m.@gma.nosp@m.il.co.nosp@m.m

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GEORGE ARGYROS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Our primary choice for a cryptographic strong randomness function is openssl_random_pseudo_bytes.

If mcrypt extension is available then we use it to gather entropy from the operating system's PRNG. This is better than reading /dev/urandom directly since it avoids reading larger blocks of data than needed. Older versions of mcrypt_create_iv may be broken or take too much time to finish so we only use this function with PHP 5.3.7 and above.

See also
https://bugs.php.net/bug.php?id=55169

No build-in crypto randomness function found. We collect any entropy available in the PHP core PRNGs along with some filesystem info and memory stats. To make this data cryptographically strong we add data either from /dev/urandom or if its unavailable, we gather entropy by measuring the time needed to compute a number of SHA-1 hashes.

Definition at line 55 of file ElggCrypto.php.

ElggCrypto::getRandomString (   $length,
  $chars = null 
)

Generate a random string of specified length.

Uses supplied character list for generating the new string. If no character list provided - uses Base64 URL character set.

Parameters
int$lengthDesired length of the string
string | null$charsCharacters to be chosen from randomly. If not given, the Base64 URL charset will be used.
Returns
string The random string
Exceptions
InvalidArgumentException
See also
https://github.com/zendframework/zf2/blob/master/library/Zend/Math/Rand.php#L179

Definition at line 183 of file ElggCrypto.php.

Member Data Documentation

const ElggCrypto::CHARS_HEX = '0123456789abcdef'

Character set for hexadecimal.

Definition at line 20 of file ElggCrypto.php.

const ElggCrypto::CHARS_PASSWORD = 'bcdfghjklmnpqrstvwxyz2346789'

Character set for temp passwords (no risk of embedded profanity/glyphs that look similar)

Definition at line 15 of file ElggCrypto.php.


The documentation for this class was generated from the following file: