函数名称:sodium_crypto_stream()
适用版本:PHP 7.2.0 及以上版本
函数说明:sodium_crypto_stream() 函数用于生成加密强度的伪随机字节流。此函数使用加密库 Sodium 提供的加密算法。
用法:
sodium_crypto_stream(int $length, string $nonce, string $key): string|false
参数:
返回值:
示例:
$length = 1024;
$nonce = random_bytes(SODIUM_CRYPTO_STREAM_NONCEBYTES);
$key = random_bytes(SODIUM_CRYPTO_STREAM_KEYBYTES);
$stream = sodium_crypto_stream($length, $nonce, $key);
if ($stream !== false) {
echo "生成的字节流: " . bin2hex($stream);
} else {
echo "生成字节流失败";
}
注意事项: