Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

openssl_random_pseudo_bytes(3) [php man page]

OPENSSL_RANDOM_PSEUDO_BYTES(3)						 1					    OPENSSL_RANDOM_PSEUDO_BYTES(3)

openssl_random_pseudo_bytes - Generate a pseudo-random string of bytes

SYNOPSIS
string openssl_random_pseudo_bytes (int $length, [bool &$crypto_strong]) DESCRIPTION
Generates a string of pseudo-random bytes, with the number of bytes determined by the $length parameter. It also indicates if a cryptographically strong algorithm was used to produce the pseudo-random bytes, and does this via the optional $crypto_strong parameter. It's rare for this to be FALSE, but some systems may be broken or old. PARAMETERS
o $length - The length of the desired string of bytes. Must be a positive integer. PHP will try to cast this parameter to a non-null integer to use it. o $crypto_strong - If passed into the function, this will hold a boolean value that determines if the algorithm used was "cryptographically strong", e.g., safe for usage with GPG, passwords, etc. TRUE if it did, otherwise FALSE RETURN VALUES
Returns the generated string of bytes on success, or FALSE on failure. EXAMPLES
Example #1 openssl_random_pseudo_bytes(3) example <?php for ($i = -1; $i <= 4; $i++) { $bytes = openssl_random_pseudo_bytes($i, $cstrong); $hex = bin2hex($bytes); echo "Lengths: Bytes: $i and Hex: " . strlen($hex) . PHP_EOL; var_dump($hex); var_dump($cstrong); echo PHP_EOL; } ?> The above example will output something similar to: Lengths: Bytes: -1 and Hex: 0 string(0) "" NULL Lengths: Bytes: 0 and Hex: 0 string(0) "" NULL Lengths: Bytes: 1 and Hex: 2 string(2) "42" bool(true) Lengths: Bytes: 2 and Hex: 4 string(4) "dc6e" bool(true) Lengths: Bytes: 3 and Hex: 6 string(6) "288591" bool(true) Lengths: Bytes: 4 and Hex: 8 string(8) "ab86d144" bool(true) SEE ALSO
random_bytes(3), bin2hex(3), crypt(3), mt_rand(3), uniqid(3). PHP Documentation Group OPENSSL_RANDOM_PSEUDO_BYTES(3)

Check Out this Related Man Page

UNIQID(3)								 1								 UNIQID(3)

uniqid - Generate a unique ID

SYNOPSIS
string uniqid ([string $prefix = ""], [bool $more_entropy = false]) DESCRIPTION
Gets a prefixed unique identifier based on the current time in microseconds. Warning This function does not create random nor unpredictable strings. This function must not be used for security purposes. Use a cryp- tographically secure random function/generator and cryptographically secure hash functions to create unpredictable secure IDs. PARAMETERS
o $prefix - Can be useful, for instance, if you generate identifiers simultaneously on several hosts that might happen to generate the iden- tifier at the same microsecond. With an empty $prefix, the returned string will be 13 characters long. If $more_entropy is TRUE, it will be 23 characters. o $more_entropy - If set to TRUE, uniqid(3) will add additional entropy (using the combined linear congruential generator) at the end of the return value, which increases the likelihood that the result will be unique. RETURN VALUES
Returns the unique identifier, as a string. EXAMPLES
Example #1 uniqid(3) Example <?php /* A uniqid, like: 4b3403665fea6 */ printf("uniqid(): %s ", uniqid()); /* We can also prefix the uniqid, this the same as * doing: * * $uniqid = $prefix . uniqid(); * $uniqid = uniqid($prefix); */ printf("uniqid('php_'): %s ", uniqid('php_')); /* We can also activate the more_entropy parameter, which is * required on some systems, like Cygwin. This makes uniqid() * produce a value like: 4b340550242239.64159797 */ printf("uniqid('', true): %s ", uniqid('', true)); ?> NOTES
Caution This function does not generate cryptographically secure tokens, in fact without being passed any additional parameters the return value is little different from microtime(3). If you need to generate cryptographically secure tokens use openssl_ran- dom_pseudo_bytes(3). Note Under Cygwin, the $more_entropy must be set to TRUE for this function to work. PHP Documentation Group UNIQID(3)
Man Page