Files
archived-doc-pt-br/reference/random/functions/random-bytes.xml
Fernando Wobeto 656473b5c2 Tradução em reference/random/functions (#657)
* inclusão dos arquivos originais com revisão atualizada

* Tradução em reference/random/functions

* Update mt-rand.xml

* Update rand.xml

* Update random-bytes.xml
2024-06-03 12:59:17 -03:00

142 lines
4.1 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: f08b9a8aee8330c248cd84b3f546391fedccd9f1 Maintainer: fernandowobeto Status: ready --><!-- CREDITS: fernandowobeto -->
<refentry xml:id="function.random-bytes" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>random_bytes</refname>
<refpurpose>Obtém bytes aleatórios criptograficamente seguros</refpurpose>
</refnamediv>
<refsect1 role="description"><!-- {{{ -->
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>random_bytes</methodname>
<methodparam><type>int</type><parameter>length</parameter></methodparam>
</methodsynopsis>
<para>
Gera uma string contendo bytes aleatórios selecionados uniformemente com o comprimento solicitado em <parameter>length</parameter>.
</para>
<para>
Como os bytes retornados são selecionados de forma completamente aleatória, é provável que a string resultante
contenha caracteres não imprimíveis ou sequências UTF-8 inválidas. Pode ser necessário
codificá-la antes da transmissão ou exibição.
</para>
<para>
A aleatoriedade gerada por esta função é adequada para todas as aplicações, incluindo
a geração de segredos de longo prazo, como chaves de criptografia.
</para>
&csprng.sources;
&csprng.function.backport;
</refsect1><!-- }}} -->
<refsect1 role="parameters"><!-- {{{ -->
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>length</parameter></term>
<listitem>
<para>
O comprimento da sequência aleatória que deve ser retornada em bytes; deve ser <literal>1</literal> ou superior.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1><!-- }}} -->
<refsect1 role="returnvalues"><!-- {{{ -->
&reftitle.returnvalues;
<para>
Uma string contendo o número solicitado de bytes aleatórios
criptograficamente seguros.
</para>
</refsect1><!-- }}} -->
<refsect1 role="errors"><!-- {{{ -->
&reftitle.errors;
<itemizedlist>
&csprng.errors;
<listitem>
<simpara>
Se o valor de <parameter>length</parameter> for menor que <literal>1</literal>,
um <classname>ValueError</classname> será lançado.
</simpara>
</listitem>
</itemizedlist>
</refsect1><!-- }}} -->
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.2.0</entry>
<entry>
No caso de uma falha de <acronym>CSPRNG</acronym>, esta função agora lançará uma
<classname>Random\RandomException</classname>. Anteriormente, uma
<classname>Exception</classname> simples era lançada.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples"><!-- {{{ -->
&reftitle.examples;
<example xml:id="random-bytes.example.basic"><!-- {{{ -->
<title>Exemplo de <function>random_bytes</function></title>
<programlisting role="php">
<![CDATA[
<?php
$bytes = random_bytes(5);
var_dump(bin2hex($bytes));
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
string(10) "385e33f741"
]]>
</screen>
</example><!-- }}} -->
</refsect1><!-- }}} -->
<refsect1 role="seealso"><!-- {{{ -->
&reftitle.seealso;
<simplelist>
<member><function>Random\Randomizer::getBytes</function></member>
<member><function>random_int</function></member>
<member><function>bin2hex</function></member>
<member><function>base64_encode</function></member>
</simplelist>
</refsect1><!-- }}} -->
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->