File "random_bytes_mcrypt.php"

Full path: /home/kosmetik/public_html/wp-includes/random_compat/random_bytes_mcrypt.php
File size: 613 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

if (!is_callable('random_bytes')) {
    function random_bytes($bytes)
    {
        try {
            $bytes = RandomCompat_intval($bytes);
        } catch (TypeError $ex) {
            throw new TypeError('random_bytes(): $bytes must be an integer');
        }
        if ($bytes < 1) {
            throw new Error('Length must be greater than 0');
        }
        $buf = @mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM);
        if ($buf !== false && RandomCompat_strlen($buf) === $bytes) {
            return $buf;
        }
        throw new Exception('Could not gather sufficient random data');
    }
}