RandomNumberGenerator.GetBytes Método

Definição

Preenche uma matriz de bytes com uma sequência de valores aleatória criptograficamente forte.Fills an array of bytes with a cryptographically strong random sequence of values.

Sobrecargas

GetBytes(Byte[])

Quando substituído em uma classe derivada, preenche uma matriz de bytes com uma sequência aleatória criptograficamente forte de valores.When overridden in a derived class, fills an array of bytes with a cryptographically strong random sequence of values.

GetBytes(Span<Byte>)

Preenche um intervalo com bytes aleatórios criptograficamente fortes.Fills a span with cryptographically strong random bytes.

GetBytes(Byte[], Int32, Int32)

Preenche a matriz de bytes especificada com uma sequência de valores aleatória e criptograficamente forte.Fills the specified byte array with a cryptographically strong random sequence of values.

GetBytes(Byte[])

Quando substituído em uma classe derivada, preenche uma matriz de bytes com uma sequência aleatória criptograficamente forte de valores.When overridden in a derived class, fills an array of bytes with a cryptographically strong random sequence of values.

public:
 abstract void GetBytes(cli::array <System::Byte> ^ data);
public abstract void GetBytes (byte[] data);
abstract member GetBytes : byte[] -> unit
Public MustOverride Sub GetBytes (data As Byte())

Parâmetros

data
Byte[]

A matriz a ser preenchida com bytes aleatórios criptograficamente fortes.The array to fill with cryptographically strong random bytes.

Exemplos

O exemplo a seguir cria uma sequência aleatória de 100 bytes e a armazena em random .The following example creates a random sequence 100 bytes long and stores it in random.

array<Byte>^ random = gcnew array<Byte>(100);

//RNGCryptoServiceProvider is an implementation of a random number generator.
RNGCryptoServiceProvider^ rng = gcnew RNGCryptoServiceProvider;
rng->GetBytes( random ); // The array is now filled with cryptographically strong random bytes.
byte[] random = new Byte[100];

//RNGCryptoServiceProvider is an implementation of a random number generator.
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetBytes(random); // The array is now filled with cryptographically strong random bytes.
Dim random() As Byte = New Byte(100) {}
       
'RNGCryptoServiceProvider is an implementation of an RNG
Dim rng As New RNGCryptoServiceProvider()
rng.GetBytes(random) ' bytes in random are now random

Comentários

O comprimento da matriz de bytes determina quantos bytes aleatórios são produzidos.The length of the byte array determines how many random bytes are produced.

Confira também

Aplica-se a

GetBytes(Span<Byte>)

Preenche um intervalo com bytes aleatórios criptograficamente fortes.Fills a span with cryptographically strong random bytes.

public:
 virtual void GetBytes(Span<System::Byte> data);
public virtual void GetBytes (Span<byte> data);
abstract member GetBytes : Span<byte> -> unit
override this.GetBytes : Span<byte> -> unit
Public Overridable Sub GetBytes (data As Span(Of Byte))

Parâmetros

data
Span<Byte>

O intervalo a ser preenchido com bytes aleatórios criptograficamente fortes.The span to fill with cryptographically strong random bytes.

Confira também

Aplica-se a

GetBytes(Byte[], Int32, Int32)

Preenche a matriz de bytes especificada com uma sequência de valores aleatória e criptograficamente forte.Fills the specified byte array with a cryptographically strong random sequence of values.

public:
 virtual void GetBytes(cli::array <System::Byte> ^ data, int offset, int count);
public virtual void GetBytes (byte[] data, int offset, int count);
abstract member GetBytes : byte[] * int * int -> unit
override this.GetBytes : byte[] * int * int -> unit
Public Overridable Sub GetBytes (data As Byte(), offset As Integer, count As Integer)

Parâmetros

data
Byte[]

A matriz a ser preenchida com bytes aleatórios criptograficamente fortes.The array to fill with cryptographically strong random bytes.

offset
Int32

O índice da matriz para iniciar a operação de preenchimento.The index of the array to start the fill operation.

count
Int32

O número de bytes a preencher.The number of bytes to fill.

Exceções

data é null.data is null.

offset ou count é menor que 0offset or count is less than 0

offset mais count excede o comprimento de data.offset plus count exceeds the length of data.

Aplica-se a