(PHP 5 >= 5.3.0, PHP 7)
openssl_random_pseudo_bytes — 锟斤拷锟斤拷一锟斤拷伪锟斤拷锟斤拷纸诖锟�
$length
[, bool &$crypto_strong
] ) : string
锟斤拷锟斤拷一锟斤拷伪锟斤拷锟斤拷纸诖锟� string 锟斤拷锟街斤拷锟斤拷锟斤拷 length
锟斤拷锟斤拷指锟斤拷锟斤拷
通锟斤拷 crypto_strong
锟斤拷锟斤拷锟斤拷锟皆憋拷示锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷纸诘墓锟斤拷锟斤拷锟斤拷欠锟绞癸拷锟斤拷锟角匡拷锟斤拷锟斤拷惴拷锟斤拷锟斤拷锟街滴�FALSE
锟斤拷锟斤拷锟斤拷锟斤拷偌锟斤拷锟斤拷锟斤拷锟斤拷鸹祷锟斤拷匣锟斤拷锟斤拷锟叫┫低筹拷匣锟斤拷锟街★拷
length
锟斤拷锟斤拷锟街节达拷锟侥筹拷锟饺o拷锟斤拷锟斤拷为锟斤拷锟斤拷锟斤拷锟斤拷PHP锟斤拷锟斤拷锟脚斤拷锟矫诧拷锟斤拷转锟斤拷为锟角匡拷锟斤拷锟斤拷锟斤拷使锟斤拷锟斤拷锟斤拷
crypto_strong
锟斤拷锟斤拷锟斤拷莸锟斤拷煤锟斤拷锟斤拷校锟斤拷锟斤拷岜o拷锟轿伙拷锟� boolean 值锟斤拷锟斤拷锟斤拷锟角凤拷使锟斤拷锟斤拷"强锟斤拷锟斤拷"锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟紾PG锟斤拷锟斤拷锟斤拷之锟斤拷慕锟斤拷锟斤拷锟�TRUE
, 锟斤拷锟津返伙拷 FALSE
锟缴癸拷锟斤拷锟斤拷锟斤拷锟斤拷锟缴碉拷锟街节达拷 string 锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE
.
Example #1 openssl_random_pseudo_bytes() 锟斤拷锟斤拷锟斤拷
<?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;
}
?>
锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�
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)